36 #ifndef INFACT_STREAM_INIT_H_
37 #define INFACT_STREAM_INIT_H_
43 #include <unordered_map>
44 #include <unordered_set>
53 using std::ostringstream;
54 using std::shared_ptr;
55 using std::unordered_map;
75 template <
typename T>
class Factory;
92 (st.
Peek() ==
"nullptr" || st.
Peek() ==
"nullptr");
95 err_ss <<
"FactoryInitializer: expected \"nullptr\", \"nullptr\" or "
96 <<
"IDENTIFIER token at stream "
119 ostringstream err_ss;
120 err_ss <<
"IntInitializer: expected NUMBER token at stream "
123 << st.
Peek() <<
"\"";
126 (*member_) = atoi(st.
Next().c_str());
141 ostringstream err_ss;
142 err_ss <<
"DoubleInitializer: expected NUMBER token at stream "
145 << st.
Peek() <<
"\"";
148 (*member_) = atof(st.
Next().c_str());
163 ostringstream err_ss;
164 err_ss <<
"BoolInitializer: expected RESERVED_WORD token at stream "
167 << st.
Peek() <<
"\"";
171 string next_tok = st.
Next();
172 if (next_tok ==
"false") {
174 }
else if (next_tok ==
"true") {
177 ostringstream err_ss;
178 err_ss <<
"Initializer<bool>: expected either \"true\" or \"false\" "
179 <<
"token at stream position " << next_tok_start <<
" but found "
180 <<
"token: \"" << next_tok <<
"\"";
197 ostringstream err_ss;
198 err_ss <<
"StringInitializer: expected STRING token at stream "
201 << st.
Peek() <<
"\"";
204 (*member_) = st.
Next();
virtual void Init(StreamTokenizer &st, Environment *env=nullptr)
virtual void Init(StreamTokenizer &st, Environment *env=nullptr)
Initializer(double *member)
string Next()
Returns the next token in the token stream.
virtual void Init(StreamTokenizer &st, Environment *env=nullptr)
Provides an error handling function that optionally throws an exception.
virtual ~StreamInitializer()
Factory for dynamically created instance of the specified type.
TokenType PeekTokenType() const
Returns the type of the next token, or EOF_TYPE if there is no next token.
virtual void Init(StreamTokenizer &st, Environment *env=nullptr)
An interface that allows for a primitive, Factory-constructible object or vector thereof to be initia...
virtual void Init(StreamTokenizer &st, Environment *env=nullptr)
Initializer(bool *member)
A simple class for tokenizing a stream of tokens for the formally specified language used to construc...
Provides the StreamTokenizer class.
A class to initialize a Factory-constructible object.
An interface for an environment in which variables of various types are mapped to their values...
static const char * TypeName(TokenType token_type)
Returns a string type name for the specified TokenType constant.
size_t PeekTokenStart() const
Returns the next token’s start position, or the byte position of the underlying byte stream if there ...
void Error(const std::string &message)
Reports an error encountered during parsing and/or construction of an object.
string Peek() const
Returns the next token that would be returned by the Next method.
shared_ptr< T > CreateOrDie(StreamTokenizer &st, Environment *env=nullptr)
Dynamically creates an object, whose type and initialization are contained in a specification string...
virtual void Init(StreamTokenizer &st, Environment *env=nullptr)=0
TokenType
The set of types of tokens read by this stream tokenizer.
Initializer(string *member)