1 //============================================================================ 2 // 3 // SSSS tt lll lll 4 // SS SS tt ll ll 5 // SS tttttt eeee ll ll aaaa 6 // SSSS tt ee ee ll ll aa 7 // SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator" 8 // SS SS tt ee ll ll aa aa 9 // SSSS ttt eeeee llll llll aaaaa 10 // 11 // Copyright (c) 1995-2021 by Bradford W. Mott, Stephen Anthony 12 // and the Stella Team 13 // 14 // See the file "License.txt" for information on usage and redistribution of 15 // this file, and for a DISCLAIMER OF ALL WARRANTIES. 16 //============================================================================ 17 18 #ifndef PROPERTIES_HXX 19 #define PROPERTIES_HXX 20 21 #include "repository/KeyValueRepository.hxx" 22 #include "bspf.hxx" 23 24 enum class PropType : uInt8 { 25 Cart_MD5, 26 Cart_Manufacturer, 27 Cart_ModelNo, 28 Cart_Name, 29 Cart_Note, 30 Cart_Rarity, 31 Cart_Sound, 32 Cart_StartBank, 33 Cart_Type, 34 Console_LeftDiff, 35 Console_RightDiff, 36 Console_TVType, 37 Console_SwapPorts, 38 Controller_Left, 39 Controller_Left1, 40 Controller_Left2, 41 Controller_Right, 42 Controller_Right1, 43 Controller_Right2, 44 Controller_SwapPaddles, 45 Controller_PaddlesXCenter, 46 Controller_PaddlesYCenter, 47 Controller_MouseAxis, 48 Display_Format, 49 Display_VCenter, 50 Display_Phosphor, 51 Display_PPBlend, 52 Cart_Highscore, 53 Cart_Url, 54 NumTypes 55 }; 56 57 /** 58 This class represents objects which maintain a collection of 59 properties. A property is a key and its corresponding value. 60 61 A properties object can contain a reference to another properties 62 object as its "defaults"; this second properties object is searched 63 if the property key is not found in the original property list. 64 65 @author Bradford W. Mott 66 */ 67 class Properties 68 { 69 friend class PropertiesSet; 70 71 public: 72 /** 73 Creates an empty properties object with the specified defaults. The 74 new properties object does not claim ownership of the defaults. 75 */ 76 Properties(); 77 78 /** 79 Creates a properties list by copying another one 80 81 @param properties The properties to copy 82 */ 83 Properties(const Properties& properties); 84 85 public: 86 void load(KeyValueRepository& repo); 87 88 bool save(KeyValueRepository& repo) const; 89 90 /** 91 Get the value assigned to the specified key. If the key does 92 not exist then the empty string is returned. 93 94 @param key The key of the property to lookup 95 @return The value of the property 96 */ get(PropType key) const97 const string& get(PropType key) const { 98 uInt8 pos = static_cast<uInt8>(key); 99 return pos < static_cast<uInt8>(PropType::NumTypes) ? myProperties[pos] : EmptyString; 100 } 101 102 /** 103 Set the value associated with key to the given value. 104 105 @param key The key of the property to set 106 @param value The value to assign to the property 107 */ 108 void set(PropType key, const string& value); 109 110 /** 111 Print the attributes of this properties object 112 */ 113 void print() const; 114 115 /** 116 Resets all properties to their defaults 117 */ 118 void setDefaults(); 119 120 /** 121 Resets the property of the given key to its default 122 123 @param key The key of the property to set 124 */ 125 void reset(PropType key); 126 127 /** 128 Overloaded equality operator(s) 129 130 @param properties The properties object to compare to 131 @return True if the properties are equal, else false 132 */ 133 bool operator == (const Properties& properties) const; 134 bool operator != (const Properties& properties) const; 135 136 /** 137 Overloaded assignment operator 138 139 @param properties The properties object to set myself equal to 140 @return Myself after assignment has taken place 141 */ 142 Properties& operator = (const Properties& properties); 143 144 /** 145 Set the default value associated with key to the given value. 146 147 @param key The key of the property to set 148 @param value The value to assign to the property 149 */ 150 static void setDefault(PropType key, const string& value); 151 152 private: 153 /** 154 Helper function to perform a deep copy of the specified 155 properties. Assumes that old properties have already been 156 freed. 157 158 @param properties The properties object to copy myself from 159 */ 160 void copy(const Properties& properties); 161 162 /** 163 Get the property type associated with the named property 164 165 @param name The PropType key associated with the given string 166 */ 167 static PropType getPropType(const string& name); 168 169 /** 170 When printing each collection of ROM properties, it is useful to 171 see which columns correspond to the output fields; this method 172 provides that output. 173 */ 174 static void printHeader(); 175 176 private: 177 static constexpr size_t NUM_PROPS = static_cast<size_t>(PropType::NumTypes); 178 179 // The array of properties 180 std::array<string, NUM_PROPS> myProperties; 181 182 // List of default properties to use when none have been provided 183 static std::array<string, NUM_PROPS> ourDefaultProperties; 184 185 // The text strings associated with each property type 186 static std::array<string, NUM_PROPS> ourPropertyNames; 187 }; 188 189 #endif 190