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 ExampleFeatureExtractor class has three members that are registered to be initialized by Factory<FeatureExtractor> (via the ExampleFeatureExtractor::RegisterInitializers method):
-
a member named
arg
of type string
,
-
a member named
strvec
of type vector<string>
and
-
a member named
b
of type bool
.
None of these is a “required” member, meaning they act like optional arguments to a constructor. The following are all legal specification strings for constructing instances of ExampleFeatureExtractor:
ExampleFeatureExtractor(arg("foo"), strvec({"foo", "bar", "baz"}), b(true))
ExampleFeatureExtractor(strvec({"foo", "bar", "baz",}))
ExampleFeatureExtractor(b(false))
ExampleFeatureExtractor()
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 conform to the following grammar:
<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> ')' |
<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> | ::= | <string_literal> [ ',' <string_literal> ]* [','] |
<double_literal> [ ',' <double_literal> ]* [','] |
<int_literal> [ ',' <int_literal> ]* [','] |
<bool_literal> [ ',' <bool_literal> ]* [','] |
<factory_init> | ::= | <member_name> '(' <spec> ')' |
<factory_vector_init> | ::= | <member_name> '(' '{' <spec_list> '}' ')' |
<spec_list> | ::= | <spec> [ ',' <spec> ]* [',']
where every <spec> has a <type> constructible by the same Factory (i.e., all <type> ’s have a common abstract base class) |
- Parameters
-
st | the stream tokenizer providing tokens according to the grammar shown above |
env | the Environment in this method was called, or NULL if there is no calling environment |
Definition at line 562 of file factory.H.