|
From: <den...@us...> - 2010-09-12 13:25:43
|
Revision: 318
http://stdair.svn.sourceforge.net/stdair/?rev=318&view=rev
Author: denis_arnaud
Date: 2010-09-12 13:25:36 +0000 (Sun, 12 Sep 2010)
Log Message:
-----------
[Test] Added a test sub-directory for Boost.Intrusive-based architecture.
Modified Paths:
--------------
trunk/stdair/configure.ac
trunk/stdair/test/Makefile.am
Added Paths:
-----------
trunk/stdair/test/archi_intru/
trunk/stdair/test/archi_intru/BomAbstract.hpp
trunk/stdair/test/archi_intru/BomRoot.hpp
trunk/stdair/test/archi_intru/FlightDate.hpp
trunk/stdair/test/archi_intru/LegDate.hpp
trunk/stdair/test/archi_intru/Makefile.am
trunk/stdair/test/archi_intru/SegmentDate.hpp
trunk/stdair/test/archi_intru/archi.cpp
trunk/stdair/test/archi_intru/intrusive.cpp
trunk/stdair/test/archi_intru/sources.mk
Modified: trunk/stdair/configure.ac
===================================================================
--- trunk/stdair/configure.ac 2010-09-10 14:01:28 UTC (rev 317)
+++ trunk/stdair/configure.ac 2010-09-12 13:25:36 UTC (rev 318)
@@ -223,6 +223,7 @@
test/samples/Makefile
test/inheritance/Makefile
test/architecture/Makefile
+ test/archi_intru/Makefile
test/mpl/Makefile
test/mpl/contrib/Makefile
test/stdair/Makefile
Modified: trunk/stdair/test/Makefile.am
===================================================================
--- trunk/stdair/test/Makefile.am 2010-09-10 14:01:28 UTC (rev 317)
+++ trunk/stdair/test/Makefile.am 2010-09-12 13:25:36 UTC (rev 318)
@@ -4,7 +4,7 @@
MAINTAINERCLEANFILES = Makefile.in
##
-SUBDIRS = samples inheritance mpl architecture stdair
+SUBDIRS = samples inheritance mpl architecture archi_intru stdair
EXTRA_DIST =
##
Property changes on: trunk/stdair/test/archi_intru
___________________________________________________________________
Added: svn:ignore
+ .deps
.libs
Makefile.in
Makefile
archi
Added: trunk/stdair/test/archi_intru/BomAbstract.hpp
===================================================================
--- trunk/stdair/test/archi_intru/BomAbstract.hpp (rev 0)
+++ trunk/stdair/test/archi_intru/BomAbstract.hpp 2010-09-12 13:25:36 UTC (rev 318)
@@ -0,0 +1,156 @@
+#ifndef __INTRUSIVE_BOM_BOMABSTRACT_HPP
+#define __INTRUSIVE_BOM_BOMABSTRACT_HPP
+
+// //////////////////////////////////////////////////////////////////////
+// Import section
+// //////////////////////////////////////////////////////////////////////
+// STL
+#include <cassert>
+#include <iosfwd>
+#include <sstream>
+#include <string>
+// Boost.Intrusive
+#include <boost/functional/hash.hpp>
+
+namespace stdair {
+
+ /** BomAbstract. */
+ class BomAbstract {
+ public:
+ /** Constructors. */
+ BomAbstract (const std::string& iKey) : _key (iKey) {}
+ BomAbstract (const int idx) {
+ std::ostringstream oStr;
+ oStr << idx;
+ _key = oStr.str();
+ }
+ /** Get the key. */
+ const std::string& getKey() const {
+ return _key;
+ }
+
+ protected:
+ /** Default constructors.
+ <br>They are kept private, so as to forbid their use (only the
+ public constructors should be used). */
+ BomAbstract () {}
+ BomAbstract (const BomAbstract&) {}
+
+ public:
+ // Comparison operators
+ friend bool operator< (const BomAbstract& a, const BomAbstract& b) {
+ return a._key < b._key;
+ }
+
+ friend bool operator> (const BomAbstract& a, const BomAbstract& b) {
+ return a._key > b._key;
+ }
+
+ friend bool operator== (const BomAbstract& a, const BomAbstract& b) {
+ return a._key == b._key;
+ }
+
+ friend bool operator!= (const BomAbstract& a, const BomAbstract& b) {
+ return a._key != b._key;
+ }
+
+ // The hash function
+ friend std::size_t hash_value (const BomAbstract& iBom) {
+ return boost::hash<std::string>() (iBom._key);
+ }
+
+ public:
+ // /////////// Display support methods /////////
+ /** Dump a Business Object into an output stream.
+ @param ostream& the output stream. */
+ virtual void toStream (std::ostream& ioOut) const = 0;
+
+ /** Read a Business Object from an input stream.
+ @param istream& the input stream. */
+ virtual void fromStream (std::istream& ioIn) = 0;
+
+ /** Get the serialised version of the Business Object. */
+ virtual std::string toString() const = 0;
+
+ protected:
+ std::string _key;
+ };
+
+}
+
+/**
+ Piece of code given by Nicolai M. Josuttis, Section 13.12.1 "Implementing
+ Output Operators" (p653) of his book "The C++ Standard Library: A Tutorial
+ and Reference", published by Addison-Wesley.
+ */
+template <class charT, class traits>
+inline
+std::basic_ostream<charT, traits>&
+operator<< (std::basic_ostream<charT, traits>& ioOut,
+ const stdair::BomAbstract& iBom) {
+ /**
+ string stream:
+ - with same format
+ - without special field width
+ */
+ std::basic_ostringstream<charT,traits> ostr;
+ ostr.copyfmt (ioOut);
+ ostr.width (0);
+
+ // Fill string stream
+ iBom.toStream (ostr);
+
+ // Print string stream
+ ioOut << ostr.str();
+
+ return ioOut;
+}
+
+/**
+ Piece of code given by Nicolai M. Josuttis, Section 13.12.1 "Implementing
+ Output Operators" (pp655-657) of his book "The C++ Standard Library:
+ A Tutorial and Reference", published by Addison-Wesley.
+ */
+template <class charT, class traits>
+inline
+std::basic_istream<charT, traits>&
+operator>> (std::basic_istream<charT, traits>& ioIn,
+ stdair::BomAbstract& ioBom) {
+ // Fill Bom object with input stream
+ ioBom.fromStream (ioIn);
+ return ioIn;
+}
+
+
+/** The disposer object function. */
+template <typename BOM>
+struct delete_disposer {
+ void operator() (BOM* oBOM_ptr) {
+ delete oBOM_ptr; oBOM_ptr = NULL;
+ }
+};
+
+// These compare (STL strings) keys of BOM objects
+template <typename BOM>
+struct StrExpComp {
+ bool operator() (const std::string& iKey, const BOM& iBom) const {
+ return (iKey < iBom.getKey());
+ }
+
+ bool operator() (const BOM& iBom, const std::string& iKey) const {
+ return (iBom.getKey() < iKey);
+ }
+};
+
+template <typename BOM>
+struct StrExpEqual {
+ bool operator() (const std::string& iKey, const BOM& iBom) const {
+ return (iKey == iBom.getKey());
+ }
+
+ bool operator() (const BOM& iBom, const std::string& iKey) const {
+ return (iBom.getKey() == iKey);
+ }
+};
+
+#endif // __INTRUSIVE_BOM_BOMABSTRACT_HPP
Added: trunk/stdair/test/archi_intru/BomRoot.hpp
===================================================================
--- trunk/stdair/test/archi_intru/BomRoot.hpp (rev 0)
+++ trunk/stdair/test/archi_intru/BomRoot.hpp 2010-09-12 13:25:36 UTC (rev 318)
@@ -0,0 +1,39 @@
+#ifndef __INTRUSIVE_BOM_BOMROOT_HPP
+#define __INTRUSIVE_BOM_BOMROOT_HPP
+
+// //////////////////////////////////////////////////////////////////////
+// Import section
+// //////////////////////////////////////////////////////////////////////
+// STL
+#include <cassert>
+#include <string>
+//
+#include <test/archi_intru/BomAbstract.hpp>
+
+namespace stdair {
+
+ /** BomRoot. */
+ class BomRoot : public BomAbstract {
+ public:
+ BomRoot (const std::string& iKey) : BomAbstract (iKey) {}
+ BomRoot (const int idx) : BomAbstract (idx) {}
+
+ 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 key. */
+ const std::string describeKey() const { return _key; }
+ };
+
+}
+#endif // __INTRUSIVE_BOM_BOMROOT_HPP
Added: trunk/stdair/test/archi_intru/FlightDate.hpp
===================================================================
--- trunk/stdair/test/archi_intru/FlightDate.hpp (rev 0)
+++ trunk/stdair/test/archi_intru/FlightDate.hpp 2010-09-12 13:25:36 UTC (rev 318)
@@ -0,0 +1,66 @@
+#ifndef __INTRUSIVE_BOM_FLIGHTDATE_HPP
+#define __INTRUSIVE_BOM_FLIGHTDATE_HPP
+
+// //////////////////////////////////////////////////////////////////////
+// Import section
+// //////////////////////////////////////////////////////////////////////
+// STL
+#include <cassert>
+#include <string>
+// Boost.Intrusive
+#include <boost/intrusive/list.hpp>
+#include <boost/intrusive/set.hpp>
+// Local
+#include <test/archi_intru/BomAbstract.hpp>
+
+/** Alias for the boost::intrusive namespace. */
+namespace bi = boost::intrusive;
+
+namespace stdair {
+
+ /** FlightDate. */
+ class FlightDate : public BomAbstract {
+ public:
+ /** Constructors. */
+ FlightDate (const std::string& iKey) : BomAbstract (iKey) {}
+ FlightDate (const int idx) : BomAbstract (idx) {}
+ /** Destructor. */
+ ~FlightDate() {}
+ private:
+ /** Default constructors.
+ <br>They are kept private, so as to forbid their use (only the
+ public constructors should be used). */
+ FlightDate () {}
+ FlightDate (const FlightDate&) {}
+
+ public:
+ bi::list_member_hook<> _childListHook;
+ bi::set_member_hook<> _childSetHook;
+
+ 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 key. */
+ const std::string describeKey() const { return _key; }
+ };
+
+ /** List of child-type FlightDate objects. */
+ typedef bi::member_hook <FlightDate, bi::list_member_hook<>,
+ &FlightDate::_childListHook> FlightDateListMemberOption;
+ typedef bi::list<FlightDate, FlightDateListMemberOption> FlightDateChildList;
+
+ typedef bi::member_hook <FlightDate, bi::set_member_hook<>,
+ &FlightDate::_childSetHook> FlightDateSetMemberOption;
+ typedef bi::set<FlightDate, FlightDateSetMemberOption> FlightDateChildSet;
+}
+#endif // __INTRUSIVE_BOM_FLIGHTDATE_HPP
Added: trunk/stdair/test/archi_intru/LegDate.hpp
===================================================================
--- trunk/stdair/test/archi_intru/LegDate.hpp (rev 0)
+++ trunk/stdair/test/archi_intru/LegDate.hpp 2010-09-12 13:25:36 UTC (rev 318)
@@ -0,0 +1,62 @@
+#ifndef __INTRUSIVE_BOM_LEGDATE_HPP
+#define __INTRUSIVE_BOM_LEGDATE_HPP
+
+// //////////////////////////////////////////////////////////////////////
+// Import section
+// //////////////////////////////////////////////////////////////////////
+// STL
+#include <cassert>
+#include <string>
+//
+#include <test/archi_intru/BomAbstract.hpp>
+
+/** Alias for the boost::intrusive namespace. */
+namespace bi = boost::intrusive;
+
+namespace stdair {
+
+ /** LegDate. */
+ class LegDate : public BomAbstract {
+ public:
+ LegDate (const std::string& iKey) : BomAbstract (iKey) {}
+ LegDate (const int idx) : BomAbstract (idx) {}
+ private:
+ /** Default constructors.
+ <br>They are kept private, so as to forbid their use (only the
+ public constructors should be used). */
+ LegDate () {}
+ LegDate (const LegDate&) {}
+
+ public:
+ bi::list_member_hook<> _childHook;
+ bi::list_member_hook<> _siblingHook;
+
+ 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 key. */
+ const std::string describeKey() const { return _key; }
+ };
+
+ /** List of child-type LegDate objects. */
+ typedef bi::member_hook <LegDate, bi::list_member_hook<>,
+ &LegDate::_childHook> LegDateChildMemberOption;
+ typedef bi::list<LegDate, LegDateChildMemberOption> LegDateChildren;
+
+ /** List of sibling-type LegDate objects. */
+ typedef bi::member_hook <LegDate, bi::list_member_hook<>,
+ &LegDate::_siblingHook> LegDateSiblingMemberOption;
+ typedef bi::list<LegDate, LegDateSiblingMemberOption> LegDateSiblings;
+
+}
+#endif // __INTRUSIVE_BOM_LEGDATE_HPP
Added: trunk/stdair/test/archi_intru/Makefile.am
===================================================================
--- trunk/stdair/test/archi_intru/Makefile.am (rev 0)
+++ trunk/stdair/test/archi_intru/Makefile.am 2010-09-12 13:25:36 UTC (rev 318)
@@ -0,0 +1,21 @@
+## test/archi_intru sub-directory
+include $(top_srcdir)/Makefile.common
+include $(srcdir)/sources.mk
+
+MAINTAINERCLEANFILES = Makefile.in
+
+##
+SUBDIRS =
+
+EXTRA_DIST =
+##
+
+check_PROGRAMS = archi
+#TESTS = $(check_PROGRAMS)
+TESTS =
+XFAIL_TESTS = #IndexBuildingTestSuite
+
+archi_SOURCES = $(archi_intru_h_sources) $(archi_intru_cc_sources)
+archi_CXXFLAGS = $(BOOST_CFLAGS)
+archi_LDFLAGS = $(BOOST_LIBS)
+archi_LDADD =
Added: trunk/stdair/test/archi_intru/SegmentDate.hpp
===================================================================
--- trunk/stdair/test/archi_intru/SegmentDate.hpp (rev 0)
+++ trunk/stdair/test/archi_intru/SegmentDate.hpp 2010-09-12 13:25:36 UTC (rev 318)
@@ -0,0 +1,64 @@
+#ifndef __INTRUSIVE_BOM_SEGMENTDATE_HPP
+#define __INTRUSIVE_BOM_SEGMENTDATE_HPP
+
+// //////////////////////////////////////////////////////////////////////
+// Import section
+// //////////////////////////////////////////////////////////////////////
+// STL
+#include <cassert>
+#include <string>
+//
+#include <test/archi_intru/BomAbstract.hpp>
+
+/** Alias for the boost::intrusive namespace. */
+namespace bi = boost::intrusive;
+
+namespace stdair {
+
+ /** SegmentDate. */
+ class SegmentDate : public BomAbstract {
+ public:
+ SegmentDate (const std::string& iKey) : BomAbstract (iKey) {}
+ SegmentDate (const int idx) : BomAbstract (idx) {}
+ private:
+ /** Default constructors.
+ <br>They are kept private, so as to forbid their use (only the
+ public constructors should be used). */
+ SegmentDate () {}
+ SegmentDate (const SegmentDate&) {}
+
+ public:
+ bi::list_member_hook<> _childHook;
+ bi::list_member_hook<> _siblingHook;
+
+ 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 key. */
+ const std::string describeKey() const { return _key; }
+ };
+
+ /** List of child-type SegmentDate objects. */
+ typedef bi::member_hook <SegmentDate, bi::list_member_hook<>,
+ &SegmentDate::_childHook> SegmentDateChildMemberOption;
+ typedef bi::list<SegmentDate,
+ SegmentDateChildMemberOption> SegmentDateChildren;
+
+ /** List of sibling-type SegmentDate objects. */
+ typedef bi::member_hook <SegmentDate, bi::list_member_hook<>,
+ &SegmentDate::_siblingHook> SegmentDateSiblingMemberOption;
+ typedef bi::list<SegmentDate,
+ SegmentDateSiblingMemberOption> SegmentDateSiblings;
+
+}
+#endif // __INTRUSIVE_BOM_SEGMENTDATE_HPP
Added: trunk/stdair/test/archi_intru/archi.cpp
===================================================================
--- trunk/stdair/test/archi_intru/archi.cpp (rev 0)
+++ trunk/stdair/test/archi_intru/archi.cpp 2010-09-12 13:25:36 UTC (rev 318)
@@ -0,0 +1,150 @@
+// STL
+#include <cassert>
+#include <iostream>
+#include <sstream>
+#include <string>
+#include <vector>
+// Boost
+#include <boost/intrusive/list.hpp>
+// Local
+#include <test/archi_intru/FlightDate.hpp>
+
+/** Alias for the boost::intrusive namespace. */
+namespace bi = boost::intrusive;
+
+
+// Optimized search functions
+stdair::FlightDate* getFromSet(const std::string& iKey,
+ stdair::FlightDateChildSet& ioFlightDateChildSet) {
+ stdair::FlightDate* oFlightDate_ptr = NULL;
+ stdair::FlightDateChildSet::iterator itFlight =
+ ioFlightDateChildSet.find (iKey, StrExpComp<stdair::FlightDate>());
+ if (itFlight == ioFlightDateChildSet.end()) {
+ return oFlightDate_ptr;
+ }
+ oFlightDate_ptr = &*itFlight;
+ return oFlightDate_ptr;
+}
+
+// /////////////////////////// M A I N /////////////////////////
+/** Main.
+ <br>Run with the following command:
+ <tt>make check && ((./bom && echo "Success") || echo "Failure")</tt>
+ <br>To run the program with Valgrind, type:
+ <tt>libtool --mode=execute valgrind --leak-check=full ./bom</tt>
+*/
+int main (int argc, char* argv[]) {
+
+ //
+ typedef std::vector<stdair::FlightDate*> FlightDateVector_T;
+
+ // Standard STL container
+ FlightDateVector_T lFlightDateVector;
+
+ // Create several FlightDate objects, each one with a different value
+ for (int idx = 0; idx < 100; ++idx) {
+ stdair::FlightDate* lFlightDate_ptr = new stdair::FlightDate (idx);
+ assert (lFlightDate_ptr != NULL);
+
+ lFlightDateVector.push_back (lFlightDate_ptr);
+ }
+
+ // (Boost) Intrusive container
+ stdair::FlightDateChildList lFlightDateChildList;
+ stdair::FlightDateChildSet lFlightDateChildSet;
+
+ // Now insert them in the same order as in vector in the member hook list
+ for (FlightDateVector_T::iterator itFlight (lFlightDateVector.begin()),
+ itend (lFlightDateVector.end()); itFlight != itend; ++itFlight) {
+ stdair::FlightDate* lFlightDate_ptr = *itFlight;
+ assert (lFlightDate_ptr != NULL);
+
+ lFlightDateChildList.push_back (*lFlightDate_ptr);
+ lFlightDateChildSet.insert (*lFlightDate_ptr);
+ }
+
+ // DEBUG
+ /*
+ std::cout << "Size of the Boost.Intrusive list of FlightDate objects: "
+ << lFlightDateChildList.size() << std::endl;
+ std::cout << "Size of the Boost.Intrusive set of FlightDate objects: "
+ << lFlightDateChildSet.size() << std::endl;
+ */
+
+ // Now test lists
+ {
+ stdair::FlightDateChildList::iterator mit (lFlightDateChildList.begin()),
+ mitend (lFlightDateChildList.end());
+ FlightDateVector_T::iterator itFlight (lFlightDateVector.begin()),
+ itend (lFlightDateVector.end());
+
+ // Test the objects inserted in the member hook list
+ for (itFlight = lFlightDateVector.begin();
+ itFlight != itend; ++itFlight, ++mit) {
+ stdair::FlightDate* lFlightDate_ptr = *itFlight;
+ assert (lFlightDate_ptr != NULL);
+
+ if (&*mit != lFlightDate_ptr) {
+ return 1;
+ }
+ }
+ }
+
+ // Now, test iterator_to()
+ {
+ stdair::FlightDateChildList::iterator itChild(lFlightDateChildList.begin());
+ for (int idx = 0; idx < 100; ++idx, ++itChild) {
+ stdair::FlightDate* lFlightDate_ptr = lFlightDateVector.at(idx);
+ assert (lFlightDate_ptr != NULL);
+
+ if (lFlightDateChildList.iterator_to (*lFlightDate_ptr) != itChild ||
+ stdair::FlightDateChildList::s_iterator_to(*lFlightDate_ptr) != itChild) {
+ return 1;
+ }
+ }
+ }
+
+ // Now, test sets
+ {
+ stdair::FlightDateChildSet::iterator itChild (lFlightDateChildSet.begin()),
+ itChildEnd (lFlightDateChildSet.end());
+ for (; itChild != itChildEnd; ++itChild) {
+ const stdair::FlightDate& lFlightDate = *itChild;
+
+ const std::string& lKey = lFlightDate.getKey();
+ stdair::FlightDate* retrievedFlightDate_ptr =
+ getFromSet (lKey, lFlightDateChildSet);
+
+ // DEBUG
+ /*
+ std::cout << "Key = '" << lKey << "', itFD = "
+ << &lFlightDate << ", retrieved: " << retrievedFlightDate_ptr
+ << std::endl;
+ */
+
+ if (retrievedFlightDate_ptr == NULL ||
+ lFlightDateChildSet.iterator_to (lFlightDate) != itChild ||
+ lFlightDateChildSet.iterator_to (*retrievedFlightDate_ptr) != itChild ||
+ stdair::FlightDateChildSet::s_iterator_to (lFlightDate) != itChild ||
+ stdair::FlightDateChildSet::s_iterator_to(*retrievedFlightDate_ptr) != itChild) {
+ return 1;
+ }
+ }
+ }
+
+
+ /** Some memory cleaning.
+ <br>Note: the FlightDate objects cannot be simply deleted (with the
+ delete opearator).
+ <br>See also, for more details:
+ - http://www.boost.org/doc/libs/1_44_0/doc/html/intrusive/usage.html#intrusive.usage.usage_lifetime
+ - http://www.boost.org/doc/libs/1_44_0/doc/html/intrusive/erasing_and_disposing.html
+ <br>First, clear simply all the Boost.Intrusive containers but one. Then,
+ clear the last Boost.Intrusive container while deleting the corresponding
+ hooked objects.
+ */
+ lFlightDateChildSet.clear();
+ lFlightDateChildList.clear_and_dispose(delete_disposer<stdair::FlightDate>());
+
+ return 0;
+}
Added: trunk/stdair/test/archi_intru/intrusive.cpp
===================================================================
--- trunk/stdair/test/archi_intru/intrusive.cpp (rev 0)
+++ trunk/stdair/test/archi_intru/intrusive.cpp 2010-09-12 13:25:36 UTC (rev 318)
@@ -0,0 +1,71 @@
+#include <boost/intrusive/list.hpp>
+#include <vector>
+
+using namespace boost::intrusive;
+
+/** Object to be inserted in the intrusive list. */
+class MyClass : public list_base_hook<> {
+ int _int;
+public:
+ list_member_hook<> member_hook_;
+
+ MyClass (int i) : _int (i) {}
+};
+
+//Define a list that will store MyClass using the base hook
+typedef list<MyClass> BaseList;
+
+//Define a list that will store MyClass using the member hook
+typedef member_hook
+<MyClass, list_member_hook<>, &MyClass::member_hook_> MemberOption;
+typedef list<MyClass, MemberOption> MemberList;
+
+
+// /////////////////////// M A I N /////////////////////
+int main() {
+
+ typedef std::vector<MyClass>::iterator VectIt;
+ typedef std::vector<MyClass>::reverse_iterator VectRit;
+
+ //Create several MyClass objects, each one with a different value
+ std::vector<MyClass> values;
+ for (int i = 0; i < 100; ++i) {
+ values.push_back (MyClass(i));
+ }
+
+ BaseList baselist;
+ MemberList memberlist;
+
+ //Now insert them in the reverse order in the base hook list
+ for (VectIt it(values.begin()), itend(values.end()); it != itend; ++it) {
+ baselist.push_front (*it);
+ }
+
+ //Now insert them in the same order as in vector in the member hook list
+ for (VectIt it(values.begin()), itend(values.end()); it != itend; ++it) {
+ memberlist.push_back (*it);
+ }
+
+ //Now test lists
+ {
+ BaseList::reverse_iterator rbit(baselist.rbegin()), rbitend(baselist.rend());
+ MemberList::iterator mit (memberlist.begin()), mitend(memberlist.end());
+ VectIt it (values.begin()), itend (values.end());
+
+ //Test the objects inserted in the base hook list
+ for (; it != itend; ++it, ++rbit) {
+ if (&*rbit != &*it) {
+ return 1;
+ }
+ }
+
+ //Test the objects inserted in the member hook list
+ for (it = values.begin(); it != itend; ++it, ++mit) {
+ if (&*mit != &*it) {
+ return 1;
+ }
+ }
+ }
+
+ return 0;
+}
Added: trunk/stdair/test/archi_intru/sources.mk
===================================================================
--- trunk/stdair/test/archi_intru/sources.mk (rev 0)
+++ trunk/stdair/test/archi_intru/sources.mk 2010-09-12 13:25:36 UTC (rev 318)
@@ -0,0 +1,8 @@
+archi_intru_h_sources = \
+ $(top_srcdir)/test/archi_intru/BomAbstract.hpp \
+ $(top_srcdir)/test/archi_intru/BomRoot.hpp \
+ $(top_srcdir)/test/archi_intru/FlightDate.hpp \
+ $(top_srcdir)/test/archi_intru/LegDate.hpp \
+ $(top_srcdir)/test/archi_intru/SegmentDate.hpp
+archi_intru_cc_sources = \
+ $(top_srcdir)/test/archi_intru/archi.cpp
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|