From: <qua...@us...> - 2010-07-28 08:46:35
|
Revision: 246 http://stdair.svn.sourceforge.net/stdair/?rev=246&view=rev Author: quannaus Date: 2010-07-28 08:46:29 +0000 (Wed, 28 Jul 2010) Log Message: ----------- [test] Added 'architecture' prototype. Modified Paths: -------------- trunk/stdair/test/architecture/Makefile.am Added Paths: ----------- trunk/stdair/test/architecture/ trunk/stdair/test/architecture/BomRoot.cpp trunk/stdair/test/architecture/BomRoot.hpp trunk/stdair/test/architecture/Inventory.cpp trunk/stdair/test/architecture/Inventory.hpp trunk/stdair/test/architecture/Structure.hpp trunk/stdair/test/architecture/StructureTypes.hpp trunk/stdair/test/architecture/architecture.cpp trunk/stdair/test/architecture/sources.mk Removed Paths: ------------- trunk/stdair/test/architecture/inherit.cpp Property changes on: trunk/stdair/test/architecture ___________________________________________________________________ Added: svn:ignore + .deps .libs Makefile Makefile.in architecture Added: svn:propedit + Copied: trunk/stdair/test/architecture/BomRoot.cpp (from rev 245, trunk/stdair/stdair/bom/BomRoot.cpp) =================================================================== --- trunk/stdair/test/architecture/BomRoot.cpp (rev 0) +++ trunk/stdair/test/architecture/BomRoot.cpp 2010-07-28 08:46:29 UTC (rev 246) @@ -0,0 +1,15 @@ +// ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// +// STL +#include <cassert> +#include "BomRoot.hpp" + +// //////////////////////////////////////////////////////////////////// +BomRoot::BomRoot (const Key_T& iKey, Structure_T& ioBomRootStructure) + : BomRootContent (iKey), _structure (ioBomRootStructure) { +} + +// //////////////////////////////////////////////////////////////////// +BomRoot::~BomRoot () { +} Copied: trunk/stdair/test/architecture/BomRoot.hpp (from rev 245, trunk/stdair/stdair/bom/BomRoot.hpp) =================================================================== --- trunk/stdair/test/architecture/BomRoot.hpp (rev 0) +++ trunk/stdair/test/architecture/BomRoot.hpp 2010-07-28 08:46:29 UTC (rev 246) @@ -0,0 +1,54 @@ +#ifndef __BOMROOT_HPP +#define __BOMROOT_HPP + +// ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// +#include <string> +#include "StructureTypes.hpp" +// StdAir +#include <stdair/bom/BomRootContent.hpp> + +/** Class representing the actual functional/business content + for the Bom root. */ +class BomRoot : public stdair::BomRootContent { +public: + /** Definition allowing to retrieve the associated BOM structure type. */ + typedef BomRootStructure_T Structure_T; + /** Definition allowing to retrieve the map/multimap type using by + BomChildrenHolder. */ + typedef std::map<const std::string, const Structure_T*> Map_T; + +public: +// /////////// Display support methods ///////// +/** Dump a Business Object into an output stream. + @param ostream& the output stream. */ +void toStream (std::ostream& ioOut) const { ioOut << toString(); } + +/** Read a Business Object from an input stream. + @param istream& the input stream. */ +void fromStream (std::istream& ioIn) { } + +/** Get the serialised version of the Business Object. */ +std::string toString() const { return describeKey(); } + +/** Get a string describing the whole key (differentiating two objects + at any level). */ +const std::string describeKey() const { return std::string (""); } + +public: +/** Constructors are private so as to force the usage of the Factory + layer. */ +/** Constructors. */ +BomRoot (const Key_T&, Structure_T&); +/** Destructor. */ +~BomRoot(); +/** Default constructors. */ +BomRoot (); +BomRoot (const BomRoot&); + +// Attributes +/** Reference structure. */ +Structure_T& _structure; +}; +#endif // __BOMROOT_HPP Copied: trunk/stdair/test/architecture/Inventory.cpp (from rev 245, trunk/stdair/stdair/bom/Inventory.cpp) =================================================================== --- trunk/stdair/test/architecture/Inventory.cpp (rev 0) +++ trunk/stdair/test/architecture/Inventory.cpp 2010-07-28 08:46:29 UTC (rev 246) @@ -0,0 +1,36 @@ +// ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// +// STL +#include <cassert> +#include "Inventory.hpp" + +// //////////////////////////////////////////////////////////////////// +Inventory::Inventory (const Key_T& iKey, + Structure_T& ioInventoryStructure) + : InventoryContent (iKey), _structure (ioInventoryStructure) { +} + +// //////////////////////////////////////////////////////////////////// +Inventory::~Inventory () { +} +// //////////////////////////////////////////////////////////////////// +void Inventory::toStream (std::ostream& ioOut) const { + ioOut << toString() << std::endl; +} + +// //////////////////////////////////////////////////////////////////// +void Inventory::fromStream (std::istream& ioIn) { +} + +// //////////////////////////////////////////////////////////////////// +std::string Inventory::toString() const { + std::ostringstream oStr; + oStr << _key.toString(); + return oStr.str(); +} + +// //////////////////////////////////////////////////////////////////// +const std::string Inventory::describeKey() const { + return _key.toString(); +} Copied: trunk/stdair/test/architecture/Inventory.hpp (from rev 245, trunk/stdair/stdair/bom/Inventory.hpp) =================================================================== --- trunk/stdair/test/architecture/Inventory.hpp (rev 0) +++ trunk/stdair/test/architecture/Inventory.hpp 2010-07-28 08:46:29 UTC (rev 246) @@ -0,0 +1,55 @@ +#ifndef __INVENTORY_HPP +#define __INVENTORY_HPP + +// ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// +#include <string> +#include "StructureTypes.hpp" +#include <stdair/bom/InventoryContent.hpp> + +class Inventory : public stdair::InventoryContent { + friend class FacBomContent; +public: + /** Definition allowing to retrieve the associated BOM structure type. */ + typedef InventoryStructure_T Structure_T; + /** Definition allowing to retrieve the map/multimap type using by + BomChildrenHolder. */ + typedef std::map<const std::string, const Structure_T*> Map_T; + +public: +// /////////// Display support methods ///////// +/** Dump a Business Object into an output stream. + @param ostream& the output stream. */ +void toStream (std::ostream& ioOut) const; + +/** Read a Business Object from an input stream. + @param istream& the input stream. */ +void fromStream (std::istream& ioIn); + +/** Get the serialised version of the Business Object. */ +std::string toString() const; + +/** Get a string describing the whole key (differentiating two objects + at any level). */ +const std::string describeKey() const; + + +public: +/** Constructors are private so as to force the usage of the Factory + layer. */ +/** Constructors. */ +Inventory (const Key_T&, Structure_T&); +/** Destructor. */ +~Inventory(); +/** Default constructors. */ +Inventory (); +Inventory (const Inventory&); + +// Attributes +/** Reference structure. */ +Structure_T& _structure; +}; + +#endif // __INVENTORY_HPP + Modified: trunk/stdair/test/architecture/Makefile.am =================================================================== --- trunk/stdair/test/inheritance/Makefile.am 2010-07-26 14:49:05 UTC (rev 245) +++ trunk/stdair/test/architecture/Makefile.am 2010-07-28 08:46:29 UTC (rev 246) @@ -1,14 +1,17 @@ ## test/inheritance sub-directory include $(top_srcdir)/Makefile.common +include $(srcdir)/sources.mk MAINTAINERCLEANFILES = Makefile.in SUBDIRS = -check_PROGRAMS = inherit +check_PROGRAMS = architecture -inherit_SOURCES = inherit.cpp -inherit_CXXFLAGS = $(BOOST_CFLAGS) -inherit_LDADD = $(BOOST_LIB) +architecture_SOURCES = $(architecture_h_sources) $(architecture_cc_sources) +architecture_CXXFLAGS = $(BOOST_CFLAGS) +architecture_LDADD = $(BOOST_LIB) +architecture_LDFLAGS = $(BOOST_PROGRAM_OPTIONS_LIB) \ + $(top_builddir)/stdair/core/libstdair.la EXTRA_DIST = Copied: trunk/stdair/test/architecture/Structure.hpp (from rev 245, trunk/stdair/stdair/bom/Structure.hpp) =================================================================== --- trunk/stdair/test/architecture/Structure.hpp (rev 0) +++ trunk/stdair/test/architecture/Structure.hpp 2010-07-28 08:46:29 UTC (rev 246) @@ -0,0 +1,171 @@ +#ifndef __STRUCTURE_HPP +#define __STRUCTURE_HPP + +// ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// +#include "StructureTypes.hpp" +#include <stdair/bom/BomStructure.hpp> +// STL +#include <cassert> + +namespace stdair { + // Forward declarations. + template <typename CONTENT> class BomChildrenHolderImp; + template <typename CONTENT> class BomMap_T; + template <typename CONTENT> class BomMultimap_T; + template <typename CONTENT> class BomList_T; +} + +/** Wrapper class aimed at holding the actual content, modeled + by a specific BomContentRoot class. */ +template <typename CONTENT> +class Structure : public stdair::BomStructure { + +public: + // Type definitions + /** Definition allowing to retrieve the associated content. */ + typedef CONTENT Content_T; + + /** Definition allowing to retrieve the associated key type. */ + typedef typename Content_T::Key_T Key_T; + + /** Definition allowing to retrieve the map of children holder type. */ + typedef typename boost::mpl::at< + ChildrenHolderMapMap_T, Content_T>::type ChildrenHolderMap_T; + + /** Definition allowing to retrieve the parent structure type. */ + typedef typename boost::mpl::at< + ParentMap_T, Content_T>::type::Structure_T Parent_T; + +public: + // ////////// Getters //////////// + /** Get the content object. */ + const Content_T& getContent () const { + assert (_content != NULL); + return *_content; + } + + /** Get the key of the content object. */ + const Key_T& getKey () const { + assert (_content != NULL); + return _content->getKey(); + } + + /** Get the parent structure. */ + const Parent_T& getParent () const { + assert (_parent != NULL); + return *_parent; + } + + /** The the holder which corresponds to the CHILD type. */ + template <typename CHILD> + stdair::BomChildrenHolderImp<CHILD>& getChildrenHolder () const { + + stdair::BomChildrenHolderImp<CHILD>* lHolder_ptr = + boost::fusion::at_key<CHILD> (_holderMap); + + assert (lHolder_ptr != NULL); + return *lHolder_ptr; + } + + /** Retrieve, if existing, the pointer of CHILD type corresponding to the + given key. + <br>If not exissting, return the NULL pointer. */ + template <typename CHILD> + CHILD* getChildPtr (const std::string& iKey) const { + CHILD* oContentChild_ptr = NULL; + + stdair::BomChildrenHolderImp<CHILD>* lHolder_ptr = + boost::fusion::at_key<CHILD> (_holderMap); + + if (lHolder_ptr != NULL) { + // Look for the child in the map, then in the multimap + stdair::BomMap_T<CHILD> lChildrenMap (*lHolder_ptr); + typename stdair::BomMap_T<CHILD>::iterator itContentChild = + lChildrenMap.find (iKey); + if (itContentChild != lChildrenMap.end()) { + oContentChild_ptr = itContentChild->second; + } + } + + return oContentChild_ptr; + } + + /** Retrieve, child of CHILD type corresponding to the given key. */ + template <typename CHILD> + CHILD& getChild (const std::string& iKey) const { + CHILD* lChild_ptr = NULL; + + const stdair::BomChildrenHolderImp<CHILD>& lHolder = getChildrenHolder<CHILD>(); + stdair::BomMap_T<CHILD> lChildrenMap (lHolder); + + typename stdair::BomMap_T<CHILD>::iterator itContentChild = + lChildrenMap.find (iKey); + + if (itContentChild != lChildrenMap.end()) { + lChild_ptr = itContentChild->second; + } + + assert (lChild_ptr != NULL); + return *lChild_ptr; + } + + // /////////// Business method //////////// + /** Initialise the pointer of children holder to NULL. */ + template <typename CHILD> + void initChildrenHolder() { + + stdair::BomChildrenHolderImp<CHILD>*& lHolder_ptr = + boost::fusion::at_key<CHILD> (_holderMap); + lHolder_ptr = NULL; + } + +public: + // /////////// Display support methods ///////// + /** Dump a Business Object into an output stream. + @param ostream& the output stream. */ + void toStream (std::ostream& ioOut) const { + ioOut << toString() << std::endl; + } + + /** Read a Business Object from an input stream. + @param istream& the input stream. */ + void fromStream (std::istream& ioIn) { } + + /** Get the serialised version of the Business Object. */ + std::string toString() const { return describeShortKey(); } + + /** Get a string describing the short key (differentiating two objects + at the same level). */ + const std::string describeShortKey() const { return getKey().toString(); } + + /** Get a string describing the parent's whole key + (differentiating two objects at any level). */ + const std::string describeParentKey() const { + assert (_parent != NULL); + return _parent->getContent().describeKey(); + } + +public: + /** Constructors are private so as to force the usage of the Factory + layer. */ + /** Default constructors. */ + Structure () : _parent (NULL), _content (NULL) { } + Structure (const Structure&) { assert (false); }; + /** Destructor. */ + ~Structure () { } + +public: + // Attributes + /** The parent structure. */ + Parent_T* _parent; + + /** The actual functional (Business Object) content. */ + Content_T* _content; + + /** The map of children holders. */ + ChildrenHolderMap_T _holderMap; +}; + +#endif // __STRUCTURE_HPP Copied: trunk/stdair/test/architecture/StructureTypes.hpp (from rev 245, trunk/stdair/stdair/bom/BomRootTypes.hpp) =================================================================== --- trunk/stdair/test/architecture/StructureTypes.hpp (rev 0) +++ trunk/stdair/test/architecture/StructureTypes.hpp 2010-07-28 08:46:29 UTC (rev 246) @@ -0,0 +1,46 @@ +// ////////////////////////////////////////////////////////////////////// +#ifndef __STRUCTURETYPES_HPP +#define __STRUCTURETYPES_HPP + +// ////////////////////////////////////////////////////////////////////// +// Import section +// ///////////////////////////////////////////// +// BOOST +#include <boost/fusion/include/map.hpp> +#include <boost/mpl/map.hpp> + +// Forward declarations. +namespace stdair { + template <typename CONTENT> class BomChildrenHolderImp; + template <typename BOM> struct BomList_T; + template <typename BOM> struct BomMap_T; +} +template <typename CONTENT> class Structure; +class BomRoot; +class Inventory; + +// ///////////////////////////////////////////////// +typedef Structure<BomRoot> BomRootStructure_T; +typedef Structure<Inventory> InventoryStructure_T; +typedef stdair::BomChildrenHolderImp<Inventory> InventoryHolder_T; +typedef stdair::BomList_T<Inventory> InventoryList_T; +typedef stdair::BomMap_T<Inventory> InventoryMap_T; + +// ///////////////////////////////////////////////// +typedef boost::mpl::map < + boost::mpl::pair<Inventory, BomRoot>, + boost::mpl::pair<BomRoot, BomRoot> > ParentMap_T; + +typedef boost::fusion::map< + boost::fusion::pair<Inventory, InventoryHolder_T*> + >BomRootChildrenHolderMap_T; +typedef boost::fusion::map< > InventoryChildrenHolderMap_T; + +typedef boost::mpl::map < + boost::mpl::pair<BomRoot, BomRootChildrenHolderMap_T>, + boost::mpl::pair<Inventory, InventoryChildrenHolderMap_T> + > ChildrenHolderMapMap_T; + + +#endif // __STRUCTURETYPES_HPP + Copied: trunk/stdair/test/architecture/architecture.cpp (from rev 245, trunk/stdair/test/inheritance/inherit.cpp) =================================================================== --- trunk/stdair/test/architecture/architecture.cpp (rev 0) +++ trunk/stdair/test/architecture/architecture.cpp 2010-07-28 08:46:29 UTC (rev 246) @@ -0,0 +1,37 @@ +// STL +#include <cassert> +#include <iostream> +#include <string> +#include <stdair/factory/FacBomContent.hpp> +#include <stdair/bom/BomSource.hpp> +#include "BomRoot.hpp" +#include "Inventory.hpp" +#include "Structure.hpp" +#include "StructureTypes.hpp" + +// ////////// M A I N ////////////// +int main (int argc, char* argv[]) { + // Step 0.0: initialisation + // Create the root of the Bom tree (i.e., a BomRoot object) + BomRoot& lBomRoot = + stdair::FacBomContent::instance().create<BomRoot>(); + + // Step 0.1: Inventory level + // Create an Inventory (BA) + const stdair::AirlineCode_T lAirlineCode ("BA"); + stdair::InventoryKey_T lInventoryKey (lAirlineCode); + + Inventory& lInventory = + stdair::FacBomContent::instance().create<Inventory>(lInventoryKey); + stdair::FacBomContent::linkWithParent (lInventory, lBomRoot); + + const InventoryList_T& lInventoryList = + lBomRoot._structure.getChildrenHolder<Inventory>(); + for (InventoryList_T::iterator itInv = lInventoryList.begin(); + itInv != lInventoryList.end(); ++itInv) { + const Inventory& lCurrentInventory = *itInv; + std::cout << "Inventory: " << lCurrentInventory.toString() << std::endl; + } + + return 0; +} Deleted: trunk/stdair/test/architecture/inherit.cpp =================================================================== --- trunk/stdair/test/inheritance/inherit.cpp 2010-07-26 14:49:05 UTC (rev 245) +++ trunk/stdair/test/architecture/inherit.cpp 2010-07-28 08:46:29 UTC (rev 246) @@ -1,81 +0,0 @@ -// STL -#include <cassert> -#include <iostream> -#include <string> - -// //////////////////////////////////// -typedef unsigned int Size_T; -typedef std::pair<Size_T, Size_T> RectangleSize_T; - -// //////////////////////////////////// -/** Rectangle */ -struct Rectangle { - - /** Constructor */ - Rectangle (const Size_T& iWidth, const Size_T& iHeight) - : _width (iWidth), _height (iHeight) { } - /** Destructor */ - virtual ~Rectangle () { } - - /** Get the size. */ - RectangleSize_T getSize() const { - return RectangleSize_T (_width, _height); - } - - /** Display. When the object is actually inherits from Rectangle, - the display() method actually called is the one of the - inheriting object. */ - virtual void display () const { - std::cout << "Hello, I am a rectangle of size (" << _width << " x " - << _height << ")" << std::endl; - } - - // //////// Attributes ///////// - /** Width, Height */ - Size_T _width; - Size_T _height; -}; - -/** Square */ -struct Square : public Rectangle { - - /** Constructor */ - Square (const Size_T& iWidth) : Rectangle (iWidth, iWidth) { } - /** Destructor */ - virtual ~Square () { } - - /** Get the size. That method overshadows the Rectangle::getSize() one. */ - Size_T getSize() const { - return _width; - } - - /** Display */ - void display () const { - std::cout << "Hello, I am a square of size (" << _width << ")" - << std::endl; - } -}; - - -// ////////// M A I N ////////////// -int main (int argc, char* argv[]) { - - Square lSquare (10); - lSquare.display(); - const Size_T& lSquareSize = lSquare.getSize(); - std::cout << " and my size is: " << lSquareSize << std::endl; - - Rectangle& lRectangle = lSquare; - lRectangle.display(); - const RectangleSize_T& lRectangleSize = lRectangle.getSize(); - std::cout << " and my size is: " << lRectangleSize.first << " x " - << lRectangleSize.second << std::endl; - - Rectangle lRectangleCopy = lSquare; - lRectangleCopy.display(); - const RectangleSize_T& lRectangleCopySize = lRectangleCopy.getSize(); - std::cout << " and my size is: " << lRectangleCopySize.first << " x " - << lRectangleCopySize.second << std::endl; - - return 0; -} Copied: trunk/stdair/test/architecture/sources.mk (from rev 245, trunk/stdair/stdair/batches/sources.mk) =================================================================== --- trunk/stdair/test/architecture/sources.mk (rev 0) +++ trunk/stdair/test/architecture/sources.mk 2010-07-28 08:46:29 UTC (rev 246) @@ -0,0 +1,7 @@ +architecture_h_sources = $(srcdir)/StructureTypes.hpp \ + $(srcdir)/Structure.hpp \ + $(srcdir)/BomRoot.hpp \ + $(srcdir)/Inventory.hpp +architecture_cc_sources = $(srcdir)/architecture.cpp \ + $(srcdir)/BomRoot.cpp \ + $(srcdir)/Inventory.cpp This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |