![]() |
Home | Libraries | People | FAQ | More |
The attr_cast<Exposed,
Transformed>()
component invokes the embedded generator while supplying an attribute
of type Transformed.
The supplied attribute gets created from the original attribute (of type
Exposed) passed to this
component using the customization point traits::transform_attribute.
// forwards to <boost/spirit/home/karma/auxiliary/attr_cast.hpp> #include <boost/spirit/include/karma_attr_cast.hpp>
Also, see Include Structure.
|
Name |
|---|
|
|
template <Exposed, Transformed> <unspecified> attr_cast(<unspecified>);
|
Parameter |
Description |
Default |
|---|---|---|
|
|
The type of the attribute supplied to the |
|
|
|
The type of the attribute expected by the embedded generator
|
|
The attr_cast is a function
template. It is possible to invoke it using the following schemes:
attr_cast(g) attr_cast<Exposed>(g) attr_cast<Exposed, Transformed>(g)
depending on which of the attribute types can be deduced properly if not explicitly specified.
Notation
gA generator object.
Semantics of an expression is defined only where it differs from, or
is not defined in UnaryGenerator.
|
Expression |
Semantics |
|---|---|
|
|
Create a component invoking the generator |
|
|
Create a component invoking the generator |
|
|
Create a component invoking the generator |
|
Expression |
Attribute |
|---|---|
|
|
|
|
|
|
|
|
|
The complexity of this component is fully defined by the complexity of the embedded generator
g.
![]() |
Note |
|---|---|
The test harness for the example(s) below is presented in the Basics Examples section. |
Some includes:
#include <boost/spirit/include/karma.hpp> #include <boost/spirit/include/support_utree.hpp> #include <boost/phoenix/core.hpp> #include <boost/phoenix/operator.hpp> #include <boost/fusion/include/std_pair.hpp> #include <boost/proto/deep_copy.hpp> #include <iostream> #include <string>
Some using declarations:
using boost::spirit::karma::int_;
The example references data structure int_data
which needs a specialization of the customization point traits::transform_attribute:
// this is just a test structure we want to use in place of an int struct int_data { int i; }; // we provide a custom attribute transformation to allow its use as an int namespace boost { namespace spirit { namespace traits { template <> struct transform_attribute<int_data const, int, karma::domain> { typedef int type; static int pre(int_data const& d) { return d.i; } }; }}}
Now we use the attr_cast
pseudo generator to invoke the attribute transformation:
int_data d = { 1 }; test_generator_attr("1", boost::spirit::karma::attr_cast(int_), d);