| 1 | /*************************************************************************** |
| 2 | * Copyright (C) 2006-2012 by Guy Rutenberg * |
| 3 | * [email protected] * |
| 4 | * * |
| 5 | * This program is free software; you can redistribute it and/or modify * |
| 6 | * it under the terms of the GNU General Public License as published by * |
| 7 | * the Free Software Foundation; either version 2 of the License, or * |
| 8 | * (at your option) any later version. * |
| 9 | * * |
| 10 | * This program is distributed in the hope that it will be useful, * |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 13 | * GNU General Public License for more details. * |
| 14 | * * |
| 15 | * You should have received a copy of the GNU General Public License * |
| 16 | * along with this program; if not, write to the * |
| 17 | * Free Software Foundation, Inc., * |
| 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
| 19 | ***************************************************************************/ |
| 20 | |
| 21 | #ifndef OPENYAHTZEE_CONFIGURATION_INC |
| 22 | #define OPENYAHTZEE_CONFIGURATION_INCcxx . . $ `src/configuration.h:22:9`! |
| 23 | |
| 24 | #include <string> |
| 25 | #include <fstream> |
| 26 | #include <map> |
| 27 | #include <list> |
| 28 | #include <boost/range/iterator_range.hpp> |
| 29 | |
| 30 | namespace configurationcxx . . $ configuration/ { |
| 31 | |
| 32 | struct HighscoreItemcxx . . $ configuration/HighscoreItem#; |
| 33 | |
| 34 | typedef stdcxx . . $ std/::listcxx . . $ std/__cxx11/list#<HighscoreItemcxx . . $ configuration/HighscoreItem#> HighscoresListcxx . . $ configuration/HighscoresList#; |
| 35 | |
| 36 | static const char* DEFAULT_HIGHSCORE_SIZEcxx . . $ configuration/DEFAULT_HIGHSCORE_SIZE. = "20"; |
| 37 | |
| 38 | class Configurationcxx . . $ configuration/Configuration# { |
| 39 | public: |
| 40 | Configurationcxx . . $ configuration/Configuration#Configuration(8d4ab0a187bf9331).(stdcxx . . $ std/::stringcxx . . $ std/string# file); |
| 41 | /** |
| 42 | * Reads Open Yahtzee configurations file and parses it. |
| 43 | */ |
| 44 | void loadcxx . . $ configuration/Configuration#load(8d4ab0a187bf9331).(stdcxx . . $ std/::stringcxx . . $ std/string# file); |
| 45 | |
| 46 | /** |
| 47 | * Saves the configurations (setting and highscores) to the file |
| 48 | * specified when the class was constructed |
| 49 | */ |
| 50 | void savecxx . . $ configuration/Configuration#save(49f6e7a06ebc5aa8).(); |
| 51 | |
| 52 | /** |
| 53 | * \return the value associated with the specified key, or empty |
| 54 | * string if that key is missing |
| 55 | */ |
| 56 | stdcxx . . $ std/::stringcxx . . $ std/string# getcxx . . $ configuration/Configuration#get(24764cae04130674).(stdcxx . . $ std/::stringcxx . . $ std/string# key, stdcxx . . $ std/::stringcxx . . $ std/string# default_value = ""cxx . . $ std/__cxx11/basic_string#basic_string(3bc0f77cdfbaa67f).); |
| 57 | /** |
| 58 | * Associates the given value with the given key. You must call |
| 59 | * save() in order to make the change permanent. |
| 60 | * \return pointer to self. |
| 61 | */ |
| 62 | Configurationcxx . . $ configuration/Configuration# *setcxx . . $ configuration/Configuration#set(f712b3a0dad3b1f).(stdcxx . . $ std/::stringcxx . . $ std/string# key, stdcxx . . $ std/::stringcxx . . $ std/string# value); |
| 63 | |
| 64 | /** |
| 65 | * Checks if a given score quallifies to the high score list |
| 66 | */ |
| 67 | bool isHighscorecxx . . $ configuration/Configuration#isHighscore(83c267b20bac841a).(int score); |
| 68 | |
| 69 | /** |
| 70 | * Adds a given entry to the highscore list. |
| 71 | * \return the place in the highscore list for the new entry, or |
| 72 | * zero if it didn't quallify. |
| 73 | */ |
| 74 | int submitHighscorecxx . . $ configuration/Configuration#submitHighscore(79b7ed53d7e910d7).(int score, stdcxx . . $ std/::stringcxx . . $ std/string# name, stdcxx . . $ std/::stringcxx . . $ std/string# date); |
| 75 | |
| 76 | const HighscoresListcxx . . $ configuration/HighscoresList#* getHighscorescxx . . $ configuration/Configuration#getHighscores(ffe7302f15546b8a).() const; |
| 77 | |
| 78 | void clearHighscorescxx . . $ configuration/Configuration#clearHighscores(49f6e7a06ebc5aa8).(); |
| 79 | |
| 80 | void setHighscoresSizecxx . . $ configuration/Configuration#setHighscoresSize(2c44cd906ae4e829).(size_t size); |
| 81 | private: |
| 82 | typedef stdcxx . . $ std/::listcxx . . $ std/__cxx11/list#<stdcxx . . $ std/::stringcxx . . $ std/string#> lines_containercxx . . $ configuration/Configuration#lines_container#; |
| 83 | typedef lines_containercxx . . $ configuration/Configuration#lines_container#::iteratorcxx . . $ std/__cxx11/list#iterator# lines_iteratorcxx . . $ configuration/Configuration#lines_iterator#; |
| 84 | |
| 85 | lines_iteratorcxx . . $ configuration/Configuration#lines_iterator# parseSettingscxx . . $ configuration/Configuration#parseSettings(73e71ecc7e5cf539).(boostcxx . . $ boost/::iterator_rangecxx . . $ boost/iterator_range#<lines_iteratorcxx . . $ configuration/Configuration#lines_iterator#> range); |
| 86 | lines_iteratorcxx . . $ configuration/Configuration#lines_iterator# parseHighscorescxx . . $ configuration/Configuration#parseHighscores(73e71ecc7e5cf539).(boostcxx . . $ boost/::iterator_rangecxx . . $ boost/iterator_range#<lines_iteratorcxx . . $ configuration/Configuration#lines_iterator#> range); |
| 87 | |
| 88 | void saveSettingscxx . . $ configuration/Configuration#saveSettings(480a71be8971737f).(stdcxx . . $ std/::ofstreamcxx . . $ std/ofstream# *file); |
| 89 | void saveHighscorescxx . . $ configuration/Configuration#saveHighscores(480a71be8971737f).(stdcxx . . $ std/::ofstreamcxx . . $ std/ofstream# *file); |
| 90 | |
| 91 | /** |
| 92 | * Loads default settings |
| 93 | */ |
| 94 | void loadDefaultSettingscxx . . $ configuration/Configuration#loadDefaultSettings(49f6e7a06ebc5aa8).(); |
| 95 | |
| 96 | stdcxx . . $ std/::mapcxx . . $ std/map#<stdcxx . . $ std/::stringcxx . . $ std/string#, stdcxx . . $ std/::stringcxx . . $ std/string#> m_settingscxx . . $ configuration/Configuration#m_settings.; |
| 97 | HighscoresListcxx . . $ configuration/HighscoresList# m_highscorescxx . . $ configuration/Configuration#m_highscores.; |
| 98 | |
| 99 | stdcxx . . $ std/::stringcxx . . $ std/string# m_filecxx . . $ configuration/Configuration#m_file.; |
| 100 | }; |
| 101 | |
| 102 | struct HighscoreItemcxx . . $ configuration/HighscoreItem# { |
| 103 | int scorecxx . . $ configuration/HighscoreItem#score.; |
| 104 | stdcxx . . $ std/::stringcxx . . $ std/string# namecxx . . $ configuration/HighscoreItem#name.; |
| 105 | stdcxx . . $ std/::stringcxx . . $ std/string# datecxx . . $ configuration/HighscoreItem#date.; |
| 106 | }; |
| 107 | |
| 108 | } |
| 109 | |
| 110 | |
| 111 | #endif |