1 | //####COPYRIGHTBEGIN#### |
---|
2 | // |
---|
3 | // ---------------------------------------------------------------------------- |
---|
4 | // Copyright (C) 1998, 1999, 2000 Red Hat, Inc. |
---|
5 | // |
---|
6 | // This program is part of the eCos host tools. |
---|
7 | // |
---|
8 | // This program is free software; you can redistribute it and/or modify it |
---|
9 | // under the terms of the GNU General Public License as published by the Free |
---|
10 | // Software Foundation; either version 2 of the License, or (at your option) |
---|
11 | // any later version. |
---|
12 | // |
---|
13 | // This program is distributed in the hope that it will be useful, but WITHOUT |
---|
14 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
---|
15 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
---|
16 | // more details. |
---|
17 | // |
---|
18 | // You should have received a copy of the GNU General Public License along with |
---|
19 | // this program; if not, write to the Free Software Foundation, Inc., |
---|
20 | // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
---|
21 | // |
---|
22 | // ---------------------------------------------------------------------------- |
---|
23 | // |
---|
24 | //####COPYRIGHTEND#### |
---|
25 | // Properties.h: interface for the CProperties class. |
---|
26 | // |
---|
27 | ////////////////////////////////////////////////////////////////////// |
---|
28 | |
---|
29 | #if !defined(AFX_PROPERTIES_H__DA938D29_135A_11D3_A50B_00A0C949ADAC__INCLUDED_) |
---|
30 | #define AFX_PROPERTIES_H__DA938D29_135A_11D3_A50B_00A0C949ADAC__INCLUDED_ |
---|
31 | |
---|
32 | #if _MSC_VER > 1000 |
---|
33 | #pragma once |
---|
34 | #endif // _MSC_VER > 1000 |
---|
35 | |
---|
36 | #include "eCosStd.h" |
---|
37 | #include "Collections.h" |
---|
38 | |
---|
39 | ////////////////////////////////////////////////////////////////////// |
---|
40 | // This class manages properties and their serialization. |
---|
41 | // What you do is this: |
---|
42 | // 1. Declare the CProperties object |
---|
43 | // 2. Call one or more "Add" functions to associate variables with names |
---|
44 | // 3. Call one of the "Load" or "Save" functions to load or save the values |
---|
45 | // There are three ways in which the "Load" or "Save" functions operate |
---|
46 | // a. Loading/saving to/from a file [LoadFromFile/SaveToFile] |
---|
47 | // In this case the contents of the file will look like |
---|
48 | // name1=value1 |
---|
49 | // name2=value2 |
---|
50 | // ... |
---|
51 | // b. Loading/saving to/from a command string [LoadFromCommandString/MakeCommandString] |
---|
52 | // In this case the contents of the string will look like |
---|
53 | // -name1=value1 -name2=value2 ... |
---|
54 | // c. Loading/saving to/from the registry [LoadFromRegistry/SaveToRegistry] |
---|
55 | // In this case the registry will contain a set of values (name1, name2,...) each of whose |
---|
56 | // value data is the corresponding value. |
---|
57 | ////////////////////////////////////////////////////////////////////// |
---|
58 | |
---|
59 | class CProperties |
---|
60 | { |
---|
61 | public: |
---|
62 | CProperties(); |
---|
63 | virtual ~CProperties(); |
---|
64 | |
---|
65 | // Declare various types of property. The functions associate names with |
---|
66 | // variables, but no values are assigned here. That comes later when a |
---|
67 | // load function (such as LoadFromRegistry) is called. |
---|
68 | void Add (LPCTSTR pszName,int &n); |
---|
69 | void Add (LPCTSTR pszName,unsigned int &n); |
---|
70 | void Add (LPCTSTR pszName,bool &b); |
---|
71 | void Add (LPCTSTR pszName,char &c); |
---|
72 | void Add (LPCTSTR pszName,unsigned char &c); |
---|
73 | void Add (LPCTSTR pszName,short&s); |
---|
74 | void Add (LPCTSTR pszName,unsigned short&s); |
---|
75 | void Add (LPCTSTR pszName,float&f); |
---|
76 | void Add (LPCTSTR pszName,double&f); |
---|
77 | void Add (LPCTSTR pszName,String &s); |
---|
78 | void Add (LPCTSTR pszName,void *d,unsigned int nLength); |
---|
79 | |
---|
80 | // Load from and save to a command string. |
---|
81 | String MakeCommandString () const; // caller must delete [] |
---|
82 | bool LoadFromCommandString (LPCTSTR psz); |
---|
83 | |
---|
84 | // Load from and save to a given file. The format is name=value, one per line. |
---|
85 | bool LoadFromFile(LPCTSTR pszFileName); |
---|
86 | bool SaveToFile (LPCTSTR pszFileName) const; |
---|
87 | |
---|
88 | #ifdef _WIN32 |
---|
89 | bool LoadFromRegistry (HKEY,LPCTSTR); |
---|
90 | bool SaveToRegistry(HKEY,LPCTSTR) const; |
---|
91 | static bool CreateKey (LPCTSTR pszKey,HKEY hKey=HKEY_CURRENT_USER); |
---|
92 | #endif |
---|
93 | |
---|
94 | protected: |
---|
95 | static bool CreatePathToFile(LPCTSTR pszDir); |
---|
96 | |
---|
97 | class CProperty { |
---|
98 | public: |
---|
99 | enum Typetype {Integer, szString, Bool, Char, Short, Float, Double, Void}; |
---|
100 | CProperty(LPCTSTR pszName,Typetype type,void *_pData); |
---|
101 | virtual ~CProperty(); |
---|
102 | friend class CProperties; |
---|
103 | bool SetValue(int n); |
---|
104 | bool SetValue(double n); |
---|
105 | bool SetValue(void *d,int nLength); |
---|
106 | bool SetValue(LPCTSTR psz); |
---|
107 | const String GetStringValue() const; |
---|
108 | unsigned long GetValue() const; |
---|
109 | |
---|
110 | protected: |
---|
111 | String strName; |
---|
112 | Typetype Type; |
---|
113 | void *pData; |
---|
114 | unsigned int nLength; // for Void |
---|
115 | }; |
---|
116 | CProperty * Lookup (LPCTSTR pszName); |
---|
117 | std::vector<CProperty> ar; // Holds declared properties |
---|
118 | }; |
---|
119 | |
---|
120 | #endif // !defined(AFX_PROPERTIES_H__DA938D29_135A_11D3_A50B_00A0C949ADAC__INCLUDED_) |
---|