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-2019 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 "bspf.hxx"
22
23enum class PropType : uInt8 {
24 Cart_MD5,
25 Cart_Manufacturer,
26 Cart_ModelNo,
27 Cart_Name,
28 Cart_Note,
29 Cart_Rarity,
30 Cart_Sound,
31 Cart_StartBank,
32 Cart_Type,
33 Console_LeftDiff,
34 Console_RightDiff,
35 Console_TVType,
36 Console_SwapPorts,
37 Controller_Left,
38 Controller_Right,
39 Controller_SwapPaddles,
40 Controller_MouseAxis,
41 Display_Format,
42 Display_YStart,
43 Display_Phosphor,
44 Display_PPBlend,
45 NumTypes
46};
47
48/**
49 This class represents objects which maintain a collection of
50 properties. A property is a key and its corresponding value.
51
52 A properties object can contain a reference to another properties
53 object as its "defaults"; this second properties object is searched
54 if the property key is not found in the original property list.
55
56 @author Bradford W. Mott
57*/
58class Properties
59{
60 friend class PropertiesSet;
61
62 public:
63 /**
64 Creates an empty properties object with the specified defaults. The
65 new properties object does not claim ownership of the defaults.
66 */
67 Properties();
68
69 /**
70 Creates a properties list by copying another one
71
72 @param properties The properties to copy
73 */
74 Properties(const Properties& properties);
75
76 public:
77 /**
78 Get the value assigned to the specified key. If the key does
79 not exist then the empty string is returned.
80
81 @param key The key of the property to lookup
82 @return The value of the property
83 */
84 const string& get(PropType key) const {
85 uInt8 pos = static_cast<uInt8>(key);
86 return pos < static_cast<uInt8>(PropType::NumTypes) ? myProperties[pos] : EmptyString;
87 }
88
89 /**
90 Set the value associated with key to the given value.
91
92 @param key The key of the property to set
93 @param value The value to assign to the property
94 */
95 void set(PropType key, const string& value);
96
97 /**
98 Load properties from the specified input stream
99
100 @param is The input stream to use
101 @param p The Properties object to write to
102 */
103 friend istream& operator>>(istream& is, Properties& p);
104
105 /**
106 Save properties to the specified output stream
107
108 @param os The output stream to use
109 @param p The Properties object to read from
110 */
111 friend ostream& operator<<(ostream& os, const Properties& p);
112
113 /**
114 Print the attributes of this properties object
115 */
116 void print() const;
117
118 /**
119 Resets all properties to their defaults
120 */
121 void setDefaults();
122
123 /**
124 Overloaded equality operator(s)
125
126 @param properties The properties object to compare to
127 @return True if the properties are equal, else false
128 */
129 bool operator == (const Properties& properties) const;
130 bool operator != (const Properties& properties) const;
131
132 /**
133 Overloaded assignment operator
134
135 @param properties The properties object to set myself equal to
136 @return Myself after assignment has taken place
137 */
138 Properties& operator = (const Properties& properties);
139
140 /**
141 Set the default value associated with key to the given value.
142
143 @param key The key of the property to set
144 @param value The value to assign to the property
145 */
146 static void setDefault(PropType key, const string& value);
147
148 private:
149 /**
150 Helper function to perform a deep copy of the specified
151 properties. Assumes that old properties have already been
152 freed.
153
154 @param properties The properties object to copy myself from
155 */
156 void copy(const Properties& properties);
157
158 /**
159 Read the next quoted string from the specified input stream
160 and returns it.
161
162 @param in The input stream to use
163 @return The string inside the quotes
164 */
165 static string readQuotedString(istream& in);
166
167 /**
168 Write the specified string to the given output stream as a
169 quoted string.
170
171 @param out The output stream to use
172 @param s The string to output
173 */
174 static void writeQuotedString(ostream& out, const string& s);
175
176 /**
177 Get the property type associated with the named property
178
179 @param name The PropType key associated with the given string
180 */
181 static PropType getPropType(const string& name);
182
183 /**
184 When printing each collection of ROM properties, it is useful to
185 see which columns correspond to the output fields; this method
186 provides that output.
187 */
188 static void printHeader();
189
190 private:
191 // The array of properties
192 string myProperties[static_cast<uInt8>(PropType::NumTypes)];
193
194 // List of default properties to use when none have been provided
195 static string ourDefaultProperties[static_cast<uInt8>(PropType::NumTypes)];
196
197 // The text strings associated with each property type
198 static const char* const ourPropertyNames[static_cast<uInt8>(PropType::NumTypes)];
199};
200
201#endif
202