Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | /* |
2 | * ========== Copyright Header Begin ========================================== | |
3 | * | |
4 | * OpenSPARC T2 Processor File: SS_ConfigObject.h | |
5 | * Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. | |
6 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES. | |
7 | * | |
8 | * The above named program is free software; you can redistribute it and/or | |
9 | * modify it under the terms of the GNU General Public | |
10 | * License version 2 as published by the Free Software Foundation. | |
11 | * | |
12 | * The above named program is distributed in the hope that it will be | |
13 | * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | * General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU General Public | |
18 | * License along with this work; if not, write to the Free Software | |
19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. | |
20 | * | |
21 | * ========== Copyright Header End ============================================ | |
22 | */ | |
23 | #ifndef __SS_ConfigObject_h__ | |
24 | #define __SS_ConfigObject_h__ | |
25 | ||
26 | #include <assert.h> | |
27 | #include <string> | |
28 | #include <list> | |
29 | #include <map> | |
30 | #include "SS_Types.h" | |
31 | ||
32 | class SS_ConfigVariable; | |
33 | class SS_ConfigString; | |
34 | class SS_ConfigNumber; | |
35 | class SS_ConfigValueList; | |
36 | ||
37 | class SS_ConfigValue/*{{{*/ | |
38 | { | |
39 | public: | |
40 | enum Type { CFG_VAR, CFG_STR, CFG_NUM, CFG_LST }; | |
41 | ||
42 | SS_ConfigValue( Type _type ) : type(_type) {} | |
43 | virtual ~SS_ConfigValue() {} | |
44 | ||
45 | bool is_var() { return type == CFG_VAR; } | |
46 | bool is_str() { return type == CFG_STR; } | |
47 | bool is_num() { return type == CFG_NUM; } | |
48 | bool is_lst() { return type == CFG_LST; } | |
49 | ||
50 | SS_ConfigVariable* var() { assert(type == CFG_VAR); return (SS_ConfigVariable*)this; } | |
51 | SS_ConfigString* str() { assert(type == CFG_STR); return (SS_ConfigString*)this; } | |
52 | SS_ConfigNumber* num() { assert(type == CFG_NUM); return (SS_ConfigNumber*)this; } | |
53 | SS_ConfigValueList* lst() { assert(type == CFG_LST); return (SS_ConfigValueList*)this; } | |
54 | ||
55 | virtual void reflect() = 0; | |
56 | ||
57 | private: | |
58 | const Type type; | |
59 | }; | |
60 | /*}}}*/ | |
61 | class SS_ConfigVariable : public SS_ConfigValue/*{{{*/ | |
62 | { | |
63 | public: | |
64 | SS_ConfigVariable( const char* _value ); | |
65 | ||
66 | void reflect(); | |
67 | ||
68 | std::string value; | |
69 | }; | |
70 | /*}}}*/ | |
71 | class SS_ConfigString : public SS_ConfigValue/*{{{*/ | |
72 | { | |
73 | public: | |
74 | SS_ConfigString( const char* _value ); | |
75 | ||
76 | void reflect(); | |
77 | ||
78 | std::string value; | |
79 | }; | |
80 | /*}}}*/ | |
81 | class SS_ConfigNumber : public SS_ConfigValue/*{{{*/ | |
82 | { | |
83 | public: | |
84 | SS_ConfigNumber( uint64_t _value ); | |
85 | ||
86 | void reflect(); | |
87 | ||
88 | uint64_t value; | |
89 | }; | |
90 | /*}}}*/ | |
91 | class SS_ConfigValueList : public SS_ConfigValue/*{{{*/ | |
92 | { | |
93 | public: | |
94 | SS_ConfigValueList() : SS_ConfigValue(CFG_LST) {} | |
95 | ~SS_ConfigValueList(); | |
96 | ||
97 | void reflect(); | |
98 | ||
99 | std::list<SS_ConfigValue*> value; | |
100 | }; | |
101 | /*}}}*/ | |
102 | ||
103 | class SS_ConfigFieldList/*{{{*/ | |
104 | { | |
105 | public: | |
106 | SS_ConfigFieldList() {} | |
107 | ~SS_ConfigFieldList(); | |
108 | ||
109 | void reflect(); | |
110 | ||
111 | std::map<std::string,SS_ConfigValue*> field; | |
112 | }; | |
113 | /*}}}*/ | |
114 | ||
115 | class SS_ConfigObject/*{{{*/ | |
116 | { | |
117 | public: | |
118 | SS_ConfigObject( const std::string& _name, const std::string& _type, SS_ConfigFieldList* _prop ); | |
119 | ~SS_ConfigObject(); | |
120 | ||
121 | void reflect(); | |
122 | ||
123 | std::string name; | |
124 | std::string type; | |
125 | SS_ConfigFieldList* prop; | |
126 | }; | |
127 | /*}}}*/ | |
128 | ||
129 | class SS_ConfigObjectList/*{{{*/ | |
130 | { | |
131 | public: | |
132 | SS_ConfigObjectList() {} | |
133 | ~SS_ConfigObjectList(); | |
134 | ||
135 | void reflect(); | |
136 | ||
137 | std::map<std::string,SS_ConfigObject*> object; | |
138 | }; | |
139 | /*}}}*/ | |
140 | ||
141 | class SS_ConfigReader/*{{{*/ | |
142 | { | |
143 | public: | |
144 | SS_ConfigReader( const char* filename ); | |
145 | ~SS_ConfigReader(); | |
146 | ||
147 | SS_ConfigValue* value( const char* object, const char* field ); | |
148 | ||
149 | void reflect(); | |
150 | ||
151 | private: | |
152 | SS_ConfigObjectList* config; | |
153 | }; | |
154 | /*}}}*/ | |
155 | ||
156 | #endif | |
157 |