Boost logo

Boost-Commit :

From: danmarsden_at_[hidden]
Date: 2007-10-28 13:40:46


Author: danmarsden
Date: 2007-10-28 13:40:45 EDT (Sun, 28 Oct 2007)
New Revision: 40534
URL: http://svn.boost.org/trac/boost/changeset/40534

Log:
Documentation for the struct extension macros
Text files modified:
   trunk/libs/fusion/doc/extension.qbk | 121 ++++++++++++++++++++++++++++++++++++++++
   1 files changed, 121 insertions(+), 0 deletions(-)

Modified: trunk/libs/fusion/doc/extension.qbk
==============================================================================
--- trunk/libs/fusion/doc/extension.qbk (original)
+++ trunk/libs/fusion/doc/extension.qbk 2007-10-28 13:40:45 EDT (Sun, 28 Oct 2007)
@@ -1,5 +1,7 @@
 [section Extension]
 
+[section The Full Extension Mechanism]
+
 The Fusion library is designed to be extensible, new sequences types can easily
 be added. In fact, the library support for `std::pair`, `boost::array` and __mpl__
 sequences is entirely provided using the extension mechanism.
@@ -375,3 +377,122 @@
 
 [endsect]
 
+[section Macros]
+
+[section BOOST_FUSION_ADAPT_STRUCT]
+
+[heading Description]
+BOOST_FUSION_ADAPT_STRUCT is a macro that can be used to generate all the
+necessary boilerplate to make an arbitrary struct into a __random_access_sequence__.
+
+[heading Synopsis]
+ BOOST_FUSION_ADAPT_STRUCT(
+ struct_name
+ (member_type0, member_name0)
+ (member_type1, member_name1)
+ ...
+ )
+
+[heading Semantics]
+ BOOST_FUSION_ADAPT_STRUCT(
+ struct_name,
+ (member_type0, member_name0)
+ (member_type1, member_name1)
+ ...
+ )
+
+The above macro generates the necessary code to adapt `struct_name`
+as a model of __random_access_sequence__. The sequence of `(member_typeN, member_nameN)`
+pairs declare the type and names of each of the struct members that will be
+part of the sequence.
+
+The macro should be used at global scope, and `struct_name` should be the fully
+namespace qualified name of the struct to be converted.
+
+[heading Header]
+ #include <boost/fusion/adapted/struct/adapt_struct.hpp>
+
+[heading Example]
+ namespace demo
+ {
+ struct employee
+ {
+ std::string name;
+ int age;
+ };
+ }
+
+ // demo::employee is now a Fusion sequence
+ BOOST_FUSION_ADAPT_STRUCT(
+ demo::employee
+ (std::string, name)
+ (int, age))
+
+[endsect]
+
+[section BOOST_FUSION_ADAPT_ASSOC_STRUCT]
+
+[heading Description]
+BOOST_FUSION_ADAPT_ASSOC_STRUCT is a macro that can be used to generate all the
+necessary boilerplate to make an arbitrary struct into a model of __random_access_sequence__
+and __associative_sequence__.
+
+[heading Synopsis]
+ BOOST_FUSION_ADAPT_ASSOC_STRUCT(
+ struct_name
+ (member_type0, member_name0, key_type0)
+ (member_type1, member_name1, key_type1)
+ ...
+ )
+
+[heading Semantics]
+ BOOST_FUSION_ADAPT_ASSOC_STRUCT(
+ struct_name
+ (member_type0, member_name0, key_type0)
+ (member_type1, member_name1, key_type1)
+ ...
+ )
+
+The above macro generates the necessary code to adapt `struct_name`
+as a model of __random_access_sequence__ and __associative_sequence__.
+The sequence of `(member_typeN, member_nameN, key_typeN)`
+triples declare the type, name and key type of each of the struct members
+that will be part of the sequence.
+
+The macro should be used at global scope, and `struct_name` should be the fully
+namespace qualified name of the struct to be converted.
+
+[heading Header]
+ #include <boost/fusion/adapted/struct/adapt_assoc_struct.hpp>
+
+[heading Example]
+ namespace demo
+ {
+ struct employee
+ {
+ std::string name;
+ int age;
+ };
+ }
+
+ namespace keys
+ {
+ struct name;
+ struct age;
+ }
+
+ // demo::employee is now a Fusion sequence
+ // It is also an associative sequence with
+ // keys keys::name and keys::age present.
+ BOOST_FUSION_ADAPT_ASSOC_STRUCT(
+ demo::employee
+ (std::string, name, keys::name)
+ (int, age, keys::age))
+
+
+[endsect]
+
+[endsect]
+
+[endsect]
+


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk