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