Dynamically creates an object, whose type and initialization are contained in a specification string, the tokens of which are given by the specified StreamTokenizer.
A specification string has the form
Typename(member1(init1), member2(init2), ...)
where the type of a member can be
-
a primitive (a
string
, double
, int
or bool
),
-
a Factory-constructible type,
-
a vector of primtives or
-
a vector of types constructible by the same Factory.
In the case of members that are vectors, the init string can be a comma-separated list of of initializers for its elements. For example, the class Cow has two members that are registered to be initialized by Factory<Cow> (via the Cow::RegisterInitializers method):
-
a member named
name
of type string
,
-
a member named
age
of type int
Only the first of these is a “required” member, meaning the age
member acts like an optional argument to a constructor. The following are all legal specification strings for constructing instances of Cow:
Cow(name("foo"), age(3))
Cow(age(3), name("foo"))
Cow(name("foo"))
Crucially, note how a vector can have an optional comma at the end of its list (the second example), and how a boolean may be initialized either with one of the two reserved words true
or false
, as in C and C++. Finally, unlike parameter lists to C++ constructors, since our members are always named, the grammar allows them to appear in any order, making the following two specification strings equivalent:
ExampleFeatureExtractor(arg("foo"), strvec({"foo", "bar", "baz"}))
ExampleFeatureExtractor(strvec({"foo", "bar", "baz"}), arg("foo"))
More formally, the specification string must be a <spec_or_null>
conforming to the following grammar:
<spec_or_null> | ::= | <spec> | 'NULL' | 'nullptr' |
<spec> | ::= | <type> '(' <member_init_list> ')' |
<type> | ::= | name of type constructible by a Factory |
<member_init_list> | ::= | <member_init> [ ',' <member_init> ]* [','] |
<member_init> | ::= | <primitive_init> | <factory_init> | <primitive_vector_init> | <factory_vector_init> |
<primitive_init> | ::= | <member_name> [ '(' <literal> ')' | '=' <literal> ] |
<member_name> | ::= | the name of the member to be initialized, as specified by <type>’s RegisterInitializers method |
<literal> | ::= | <string_literal> | <double_literal> | <int_literal> | <bool_literal> |
<string_literal> | ::= | a C++ string literal (a string of characters surrounded by double quotes); double quotes and backslashes may be escaped inside a string literal with a backslash; other escape sequences, such as \t for the tab character, are currently not recognized |
<double_literal> | ::= | a string that can be parsed by atof |
<int_literal> | ::= | a string that can be parsed by atoi |
<bool_literal> | ::= | true | false |
<primitive_vector_init> | ::= | <member_name> [ '(' '{' <literal_list> '}' ')' | '=' '{' <literal_list> '}' |
<literal_list> | ::= | <string_literal> [ ',' <string_literal> ]* [','] |
<double_literal> [ ',' <double_literal> ]* [','] |
<int_literal> [ ',' <int_literal> ]* [','] |
<bool_literal> [ ',' <bool_literal> ]* [','] |
<factory_init> | ::= | <member_name> [ '(' <spec_or_null> ')' | '=' <spec_or_null> ] |
<factory_vector_init> | ::= | <member_name> [ '(' '{' <spec_list> '}' ')' | '=' '{' <spec_list> '}' |
<spec_list> | ::= | <spec_or_null> [ ',' <spec_or_null> ]* [',']
where every <spec_or_null> has a <type> constructible by the same Factory (i.e., all <type> ’s have a common abstract base class), or is either 'NULL' or 'nullptr' |
- Parameters
-
st | the stream tokenizer providing tokens according to the grammar shown above |
env | the Environment in this method was called, or nullptr if there is no calling environment |
Definition at line 766 of file factory.h.