| 65 | namespace olc::utils |
| 66 | { |
| 67 | class datafile |
| 68 | { |
| 69 | public: |
| 70 | inline datafile() = default; |
| 71 | |
| 72 | public: |
| 73 | // Sets the String Value of a Property (for a given index) |
| 74 | inline void SetString(const std::string& sString, const size_t nItem = 0) |
| 75 | { |
| 76 | if (nItem >= m_vContent.size()) |
| 77 | m_vContent.resize(nItem + 1); |
| 78 | |
| 79 | m_vContent[nItem] = sString; |
| 80 | } |
| 81 | |
| 82 | // Retrieves the String Value of a Property (for a given index) or "" |
| 83 | inline const std::string GetString(const size_t nItem = 0) const |
| 84 | { |
| 85 | if (nItem >= m_vContent.size()) |
| 86 | return ""; |
| 87 | else |
| 88 | return m_vContent[nItem]; |
| 89 | } |
| 90 | |
| 91 | // Retrieves the Real Value of a Property (for a given index) or 0.0 |
| 92 | inline const double GetReal(const size_t nItem = 0) const |
| 93 | { |
| 94 | return std::atof(GetString(nItem).c_str()); |
| 95 | } |
| 96 | |
| 97 | // Sets the Real Value of a Property (for a given index) |
| 98 | inline void SetReal(const double d, const size_t nItem = 0) |
| 99 | { |
| 100 | SetString(std::to_string(d), nItem); |
| 101 | } |
| 102 | |
| 103 | // Retrieves the Integer Value of a Property (for a given index) or 0 |
| 104 | inline const int32_t GetInt(const size_t nItem = 0) const |
| 105 | { |
| 106 | return std::atoi(GetString(nItem).c_str()); |
| 107 | } |
| 108 | |
| 109 | // Sets the Integer Value of a Property (for a given index) |
| 110 | inline void SetInt(const int32_t n, const size_t nItem = 0) |
| 111 | { |
| 112 | SetString(std::to_string(n), nItem); |
| 113 | } |
| 114 | |
| 115 | // Returns the number of Values a property consists of |
| 116 | inline size_t GetValueCount() const |
| 117 | { |
| 118 | return m_vContent.size(); |
| 119 | } |
| 120 | |
| 121 | // Checks if a property exists - useful to avoid creating properties |
| 122 | // via reading them, though non-essential |
| 123 | inline bool HasProperty(const std::string& sName) const |
| 124 | { |