OpenASIP 2.2
Loading...
Searching...
No Matches
ConfigurationFile.hh
Go to the documentation of this file.
1/*
2 Copyright (c) 2002-2009 Tampere University.
3
4 This file is part of TTA-Based Codesign Environment (TCE).
5
6 Permission is hereby granted, free of charge, to any person obtaining a
7 copy of this software and associated documentation files (the "Software"),
8 to deal in the Software without restriction, including without limitation
9 the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 and/or sell copies of the Software, and to permit persons to whom the
11 Software is furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 DEALINGS IN THE SOFTWARE.
23 */
24/**
25 * @file ConfigurationFile.hh
26 *
27 * Declaration of ConfigurationFile class.
28 *
29 * @author Jussi Nykänen 2004 (nykanen-no.spam-cs.tut.fi)
30 * @author Pekka Jääskeläinen 2007 (pjaaskel-no.spam-cs.tut.fi)
31 * @note rating: red
32 */
33
34#ifndef TTA_CONFIGURATION_FILE_HH
35#define TTA_CONFIGURATION_FILE_HH
36
37#include <map>
38#include <string>
39#include <vector>
40
41#include "Exception.hh"
42#include "TCEString.hh"
43
44/**
45 * Class that is able to read files with key-value-pairs, such as the processor
46 * configuration file.
47 *
48 * Can do simple sanity and type checking of the file while loading it.
49 */
51public:
52 ConfigurationFile(bool doChecking = false);
53 virtual ~ConfigurationFile();
54
55 void load(std::istream& inputStream);
56
57 bool hasKey(const std::string& key);
58 std::string value(const std::string& key, int index = 0);
59
60 int itemCount(const std::string& key);
61
62 int intValue(const std::string& key, int index = 0);
63 float floatValue(const std::string& key, int index = 0);
64 std::string stringValue(const std::string& key, int index = 0);
65 bool booleanValue(const std::string& key, int index = 0);
66
67 unsigned int timeStampValue(const std::string& key);
68
69protected:
70 /**
71 * Different value types.
72 */
74 VT_INTEGER, ///< Integer value.
75 VT_FLOAT, ///< Float value.
76 VT_STRING, ///< String value.
77 VT_BOOLEAN, ///< Boolean value.
78 VT_READABLE_TIME, ///< Time in readable format.
79 VT_UNIX_TIMESTAMP ///< Time as seconds since starting of 1970.
80 };
81
82 /**
83 * Error types.
84 */
86 FE_SYNTAX, ///< Syntax error.
87 FE_ILLEGAL_TYPE, ///< Illegal type error.
88 FE_UNKNOWN_KEY, ///< Unknown key error.
89 FE_MISSING_VALUE ///< Missing value error.
90 };
91
92 void addSupportedKey(
93 const std::string& key,
95 bool caseSensitive = false);
96
97 virtual bool handleError(
98 int lineNumber,
100 const std::string& line);
101
102private:
103 struct Key;
104 typedef std::map<TCEString, std::vector<TCEString> > ValueContainer;
105
106 // potential indeterminism?
107 typedef std::map<Key*, ConfigurationValueType> KeyContainer;
108
109 void parse(std::istream& inputStream);
110 bool checkSemantics(
111 const std::string& key,
112 const std::string& value,
113 int lineNumber,
114 const std::string& line);
115 bool isComment(const std::string& line);
116 bool legalTime(const std::string& line);
117 std::string valueOfKey(const std::string& key, int index);
118
119 /**
120 * Key.
121 */
122 struct Key {
123 /**
124 * Constructor.
125 */
127 /// Name of the key.
128 std::string name_;
129 /// True if name is case sensitive.
131 };
132
133 /// True if semantics of the configuration file is checked.
134 bool check_;
135 /// Contains all the values of configuration file.
137 /// Contains all the legal keys of the configuration file.
139};
140
141#endif
find Finds info of the inner loops in the false
virtual bool handleError(int lineNumber, ConfigurationFileError error, const std::string &line)
std::map< TCEString, std::vector< TCEString > > ValueContainer
void addSupportedKey(const std::string &key, ConfigurationValueType type, bool caseSensitive=false)
bool checkSemantics(const std::string &key, const std::string &value, int lineNumber, const std::string &line)
void load(std::istream &inputStream)
std::map< Key *, ConfigurationValueType > KeyContainer
bool isComment(const std::string &line)
KeyContainer keys_
Contains all the legal keys of the configuration file.
unsigned int timeStampValue(const std::string &key)
int itemCount(const std::string &key)
bool legalTime(const std::string &line)
int intValue(const std::string &key, int index=0)
bool check_
True if semantics of the configuration file is checked.
std::string valueOfKey(const std::string &key, int index)
ValueContainer values_
Contains all the values of configuration file.
bool hasKey(const std::string &key)
bool booleanValue(const std::string &key, int index=0)
std::string stringValue(const std::string &key, int index=0)
@ FE_UNKNOWN_KEY
Unknown key error.
@ FE_SYNTAX
Syntax error.
@ FE_MISSING_VALUE
Missing value error.
@ FE_ILLEGAL_TYPE
Illegal type error.
void parse(std::istream &inputStream)
@ VT_UNIX_TIMESTAMP
Time as seconds since starting of 1970.
@ VT_STRING
String value.
@ VT_READABLE_TIME
Time in readable format.
@ VT_BOOLEAN
Boolean value.
@ VT_INTEGER
Integer value.
float floatValue(const std::string &key, int index=0)
std::string value(const std::string &key, int index=0)
std::string name_
Name of the key.
bool caseSensitive_
True if name is case sensitive.