102 EntryBase(
const std::string &name,
char delim =
' ',
bool req =
true) :
103 key(name), delimiter(delim), required(req), valid(
false) {}
104 virtual ~EntryBase() {}
106 std::string GetKey()
const {
return key; }
107 bool isRequired()
const {
return required; }
108 bool isValid()
const {
return valid; }
109 void SetValid(
bool val) { valid = val; }
112 virtual bool Parse(std::istream &
CMN_UNUSED(inputStream)) {
return false; }
113 virtual void ToStream(std::ostream & outputStream)
const { outputStream << key <<
" (default)"; }
116 template <
class _elementType>
117 class Entry :
public EntryBase {
118 _elementType *valuePtr;
120 Entry(
const std::string &name, _elementType &data,
char delim =
' ',
bool req =
true) :
121 EntryBase(name, delim, req), valuePtr(&data) {}
124 bool Parse(std::istream &inputStream) {
133 catch (
const std::runtime_error &) {
140 void ToStream(std::ostream & outputStream)
const {
141 outputStream << key <<
" ";
142 if (valuePtr && valid) {
146 catch (
const std::runtime_error &e) {
147 outputStream <<
"(invalid: " << e.what() <<
")";
151 outputStream <<
"(invalid)";
155 template <
class _elementType>
156 class EntryStreamable :
public EntryBase {
157 _elementType *valuePtr;
159 EntryStreamable(
const std::string &name, _elementType &data,
bool req =
true) :
160 EntryBase(name,
' ', req), valuePtr(&data) {}
161 ~EntryStreamable() {}
163 bool Parse(std::istream &inputStream) {
168 inputStream >> *valuePtr;
169 valid = inputStream.good();
173 void ToStream(std::ostream & outputStream)
const {
174 outputStream << key <<
" ";
175 if (valuePtr && valid)
176 outputStream << *valuePtr;
178 outputStream <<
"(invalid)";
183 struct KeyListLess:
public std::binary_function<const cmnStreamRawParser::EntryBase*, const cmnStreamRawParser::EntryBase*, bool>
185 result_type
operator()(first_argument_type p1, second_argument_type p2)
const
187 return p1->GetKey() < p2->GetKey();
191 typedef std::set<cmnStreamRawParser::EntryBase *, KeyListLess> KeyListType;
204 template <
class _elementType>
205 bool AddEntry(
const std::string &name, _elementType &data,
char delim =
' ',
bool req =
true)
207 cmnStreamRawParser::EntryBase *newEntry =
new Entry<_elementType>(name, data, delim, req);
208 bool result = KeyList.insert(newEntry).second;
209 if (!result)
delete newEntry;
220 template <
class _elementType>
223 cmnStreamRawParser::EntryBase *newEntry =
new EntryStreamable<_elementType>(name, data, req);
224 bool result = KeyList.insert(newEntry).second;
225 if (!result)
delete newEntry;
234 bool Parse(std::istream & inputStream);
bool AddEntry(const std::string &name, _elementType &data, char delim=' ', bool req=true)
Definition cmnStreamRawParser.h:205
const_reference operator()(size_type rowIndex, size_type colIndex) const CISST_THROW(std
Definition vctDynamicConstMatrixBase.h:352