FreeCalypso > hg > leo2moko-debug
comparison gpf/INC/pco_inifile.h @ 0:509db1a7b7b8
initial import: leo2moko-r1
author | Space Falcon <falcon@ivan.Harhan.ORG> |
---|---|
date | Mon, 01 Jun 2015 03:24:05 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:509db1a7b7b8 |
---|---|
1 /* | |
2 +----------------------------------------------------------------------------- | |
3 | Project : PCO2 | |
4 | Modul : inc\pco_inifile.h | |
5 +----------------------------------------------------------------------------- | |
6 | Copyright 2002 Texas Instruments Berlin, AG | |
7 | All rights reserved. | |
8 | | |
9 | This file is confidential and a trade secret of Texas | |
10 | Instruments Berlin, AG | |
11 | The receipt of or possession of this file does not convey | |
12 | any rights to reproduce or disclose its contents or to | |
13 | manufacture, use, or sell anything it may describe, in | |
14 | whole, or in part, without the specific written consent of | |
15 | Texas Instruments Berlin, AG. | |
16 +----------------------------------------------------------------------------- | |
17 | Purpose : Contains declarations of the class IniFile. (Based on | |
18 | File from Adam Clauss) | |
19 +----------------------------------------------------------------------------- | |
20 */ | |
21 | |
22 #ifndef _PCO_INIFILE_H_ | |
23 #define _PCO_INIFILE_H_ | |
24 | |
25 /*==== INCLUDES ===================================================*/ | |
26 | |
27 #pragma warning (disable: 4786) /* ignore warning about to long template names */ | |
28 | |
29 #include <iostream> | |
30 #include <string> | |
31 #include <vector> | |
32 #include "cms.h" | |
33 | |
34 using namespace std; | |
35 | |
36 /*==== PROTOTYPES ==================================================*/ | |
37 | |
38 //all Keys are of this type | |
39 struct Key | |
40 { | |
41 //list of values in key | |
42 vector<string> values; | |
43 | |
44 //corresponding list of value names | |
45 vector<string> names; | |
46 | |
47 //corresponding list of modified state | |
48 vector<bool> modified; | |
49 }; | |
50 | |
51 class IniFile | |
52 { | |
53 //all private variables | |
54 private: | |
55 | |
56 //stores pathname of ini file to read/write | |
57 string path; | |
58 | |
59 //list of Keys in ini | |
60 vector<Key> keys; | |
61 | |
62 //corresponding list of Keynames | |
63 vector<string> names; | |
64 | |
65 // semaphore to protect file reading/writing | |
66 CMS_HANDLE m_file_sema; | |
67 | |
68 //all private functions | |
69 private: | |
70 //overloaded to take string | |
71 istream & getline( istream & is, string & str ); | |
72 | |
73 //returns index of specified value, in the specified Key, or -1 if not found | |
74 int FindValue(int Keynum, string valuename) const; | |
75 | |
76 //returns index of specified Key, or -1 if not found | |
77 int FindKey(string Keyname) const; | |
78 | |
79 | |
80 //public variables | |
81 public: | |
82 | |
83 //will contain error info if one occurs | |
84 //ended up not using much, just in ReadFile and GetValue | |
85 mutable string error; | |
86 | |
87 //will contain warning info if one occurs | |
88 //ended up not using much, just in ReadFile | |
89 mutable string warning; | |
90 | |
91 //public functions | |
92 public: | |
93 //default constructor | |
94 IniFile(); | |
95 | |
96 //constructor, can specify pathname here instead of using SetPath later | |
97 IniFile(string inipath); | |
98 | |
99 //default destructor | |
100 virtual ~IniFile(); | |
101 | |
102 //sets path of ini file to read and write from | |
103 void SetPath(string newpath); | |
104 | |
105 //returns path of currently selected ini file | |
106 const char* GetPath() const { return path.c_str();} | |
107 | |
108 //reads ini file specified using IniFile::SetPath() | |
109 //returns true if successful, false otherwise | |
110 //may contain warnings in warning-variable | |
111 bool ReadFile(bool refresh=false); | |
112 | |
113 //writes data stored in class to ini file | |
114 bool WriteFile(bool refresh_first=true); | |
115 | |
116 //deletes all stored ini data | |
117 void Reset(); | |
118 | |
119 //returns number of Keys currently in the ini | |
120 int GetNumKeys() const; | |
121 | |
122 //returns number of values stored for specified Key | |
123 int GetNumValues(string Keyname) const; | |
124 | |
125 //gets value of [Keyname] valuename = | |
126 //overloaded to return string, int, and double, | |
127 //returns "", or 0 if Key/value not found. Sets error member to show problem | |
128 string GetValue(string Keyname, string valuename) const; | |
129 int GetValueI(string Keyname, string valuename) const; | |
130 double GetValueF(string Keyname, string valuename) const; | |
131 | |
132 //sets value of [Keyname] valuename =. | |
133 //specify the optional paramter as false (0) if you do not want it to create | |
134 //the Key if it doesn't exist. Returns true if data entered, false otherwise | |
135 //overloaded to accept string, int, and double | |
136 bool SetValue(string Key, string valuename, string value, bool create = 1); | |
137 bool SetValueI(string Key, string valuename, int value, bool create = 1); | |
138 bool SetValueF(string Key, string valuename, double value, bool create = 1); | |
139 | |
140 bool modified(string keyname, string valuename); | |
141 bool set_modified(string keyname, string valuename, bool modified=true); | |
142 | |
143 //deletes specified value | |
144 //returns true if value existed and deleted, false otherwise | |
145 bool DeleteValue(string Keyname, string valuename); | |
146 | |
147 //deletes specified Key and all values contained within | |
148 //returns true if Key existed and deleted, false otherwise | |
149 bool DeleteKey(string Keyname); | |
150 }; | |
151 | |
152 #endif /* _PCO_INIFILE_H_ */ |