| 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_SET_HXX | 
|---|
| 19 | #define PROPERTIES_SET_HXX | 
|---|
| 20 |  | 
|---|
| 21 | #include <map> | 
|---|
| 22 |  | 
|---|
| 23 | class FilesystemNode; | 
|---|
| 24 | class OSystem; | 
|---|
| 25 |  | 
|---|
| 26 | #include "bspf.hxx" | 
|---|
| 27 | #include "Props.hxx" | 
|---|
| 28 |  | 
|---|
| 29 | /** | 
|---|
| 30 | This class maintains an ordered collection of properties, maintained | 
|---|
| 31 | in a C++ map and accessible by ROM md5.  The md5 is used since this is | 
|---|
| 32 | the attribute which must be present in each entry in stella.pro | 
|---|
| 33 | and least likely to change.  A change in MD5 would mean a change in | 
|---|
| 34 | the game rom image (essentially a different game) and this would | 
|---|
| 35 | necessitate a new entry in the stella.pro file anyway. | 
|---|
| 36 |  | 
|---|
| 37 | @author  Stephen Anthony | 
|---|
| 38 | */ | 
|---|
| 39 | class PropertiesSet | 
|---|
| 40 | { | 
|---|
| 41 | public: | 
|---|
| 42 | /** | 
|---|
| 43 | Trivial constructor. | 
|---|
| 44 | */ | 
|---|
| 45 | PropertiesSet() = default; | 
|---|
| 46 |  | 
|---|
| 47 | /** | 
|---|
| 48 | Load properties from the specified file, and create an internal | 
|---|
| 49 | searchable list. | 
|---|
| 50 |  | 
|---|
| 51 | @param filename  Full pathname of input file to use | 
|---|
| 52 | */ | 
|---|
| 53 | void load(const string& filename); | 
|---|
| 54 |  | 
|---|
| 55 | /** | 
|---|
| 56 | Save properties to the specified file. | 
|---|
| 57 |  | 
|---|
| 58 | @param filename  Full pathname of output file to use | 
|---|
| 59 |  | 
|---|
| 60 | @return  True on success, false on failure or save not needed | 
|---|
| 61 | Failure occurs if file couldn't be opened for writing, | 
|---|
| 62 | or if the file doesn't exist and a zero-byte file | 
|---|
| 63 | would be created | 
|---|
| 64 | */ | 
|---|
| 65 | bool save(const string& filename) const; | 
|---|
| 66 |  | 
|---|
| 67 | /** | 
|---|
| 68 | Get the property from the set with the given MD5. | 
|---|
| 69 |  | 
|---|
| 70 | @param md5         The md5 of the property to get | 
|---|
| 71 | @param properties  The properties with the given MD5, or the default | 
|---|
| 72 | properties if not found | 
|---|
| 73 | @param useDefaults  Use the built-in defaults, ignoring any properties | 
|---|
| 74 | from an external file | 
|---|
| 75 |  | 
|---|
| 76 | @return  True if the set with the specified md5 was found, else false | 
|---|
| 77 | */ | 
|---|
| 78 | bool getMD5(const string& md5, Properties& properties, | 
|---|
| 79 | bool useDefaults = false) const; | 
|---|
| 80 |  | 
|---|
| 81 | /** | 
|---|
| 82 | Get the property from the set with the given MD5, at the same time | 
|---|
| 83 | checking if it exists.  If it doesn't, insert a temporary copy into | 
|---|
| 84 | the set. | 
|---|
| 85 |  | 
|---|
| 86 | @param rom         The ROM file used to calculate the MD5 | 
|---|
| 87 | @param md5         The md5 of the property to get | 
|---|
| 88 | @param properties  The properties with the given MD5, or the default | 
|---|
| 89 | properties if not found | 
|---|
| 90 | */ | 
|---|
| 91 | void getMD5WithInsert(const FilesystemNode& rom, const string& md5, | 
|---|
| 92 | Properties& properties); | 
|---|
| 93 |  | 
|---|
| 94 | /** | 
|---|
| 95 | Insert the properties into the set.  If a duplicate is inserted | 
|---|
| 96 | the old properties are overwritten with the new ones. | 
|---|
| 97 |  | 
|---|
| 98 | @param properties  The collection of properties | 
|---|
| 99 | @param save        Indicates whether the properties should be saved | 
|---|
| 100 | when the program exits | 
|---|
| 101 | */ | 
|---|
| 102 | void insert(const Properties& properties, bool save = true); | 
|---|
| 103 |  | 
|---|
| 104 | /** | 
|---|
| 105 | Prints the contents of the PropertiesSet as a flat file. | 
|---|
| 106 | */ | 
|---|
| 107 | void print() const; | 
|---|
| 108 |  | 
|---|
| 109 | private: | 
|---|
| 110 | using PropsList = std::map<string, Properties>; | 
|---|
| 111 |  | 
|---|
| 112 | // The properties read from an external 'stella.pro' file | 
|---|
| 113 | PropsList myExternalProps; | 
|---|
| 114 |  | 
|---|
| 115 | // The properties temporarily inserted by the program, which should | 
|---|
| 116 | // be discarded when the program ends | 
|---|
| 117 | PropsList myTempProps; | 
|---|
| 118 |  | 
|---|
| 119 | private: | 
|---|
| 120 | // Following constructors and assignment operators not supported | 
|---|
| 121 | PropertiesSet(const PropertiesSet&) = delete; | 
|---|
| 122 | PropertiesSet(PropertiesSet&&) = delete; | 
|---|
| 123 | PropertiesSet& operator=(const PropertiesSet&) = delete; | 
|---|
| 124 | PropertiesSet& operator=(PropertiesSet&&) = delete; | 
|---|
| 125 | }; | 
|---|
| 126 |  | 
|---|
| 127 | #endif | 
|---|
| 128 |  | 
|---|