|
From: <den...@us...> - 2010-09-11 16:51:23
|
Revision: 130
http://dsim.svn.sourceforge.net/dsim/?rev=130&view=rev
Author: denis_arnaud
Date: 2010-09-11 16:51:17 +0000 (Sat, 11 Sep 2010)
Log Message:
-----------
[Test] Added C++ classes to demonstrate how to use Boost.Intrusive for the BOM tree (there is still some work).
Modified Paths:
--------------
trunk/dsim/test/boost/intrusive/Makefile.am
Added Paths:
-----------
trunk/dsim/test/boost/intrusive/BomAbstract.hpp
trunk/dsim/test/boost/intrusive/BomRoot.hpp
trunk/dsim/test/boost/intrusive/FlightDate.hpp
trunk/dsim/test/boost/intrusive/LegDate.hpp
trunk/dsim/test/boost/intrusive/SegmentDate.hpp
trunk/dsim/test/boost/intrusive/bom.cpp
trunk/dsim/test/boost/intrusive/sources.mk
Property Changed:
----------------
trunk/dsim/test/boost/intrusive/
Property changes on: trunk/dsim/test/boost/intrusive
___________________________________________________________________
Modified: svn:ignore
- .deps
.libs
Makefile.in
Makefile
intrusive
+ .deps
.libs
Makefile.in
Makefile
intrusive
bom
Added: trunk/dsim/test/boost/intrusive/BomAbstract.hpp
===================================================================
--- trunk/dsim/test/boost/intrusive/BomAbstract.hpp (rev 0)
+++ trunk/dsim/test/boost/intrusive/BomAbstract.hpp 2010-09-11 16:51:17 UTC (rev 130)
@@ -0,0 +1,28 @@
+#ifndef __INTRUSIVE_BOM_BOMABSTRACT_HPP
+#define __INTRUSIVE_BOM_BOMABSTRACT_HPP
+
+// //////////////////////////////////////////////////////////////////////
+// Import section
+// //////////////////////////////////////////////////////////////////////
+// STL
+#include <cassert>
+#include <sstream>
+#include <string>
+
+namespace intrusive {
+
+ /** BomAbstract. */
+ class BomAbstract {
+ public:
+ BomAbstract (const std::string& iKey) : _key (iKey) {}
+ BomAbstract (const int idx) {
+ std::ostringstream oStr;
+ oStr << idx;
+ _key = oStr.str();
+ }
+ protected:
+ std::string _key;
+ };
+
+}
+#endif // __INTRUSIVE_BOM_BOMABSTRACT_HPP
Added: trunk/dsim/test/boost/intrusive/BomRoot.hpp
===================================================================
--- trunk/dsim/test/boost/intrusive/BomRoot.hpp (rev 0)
+++ trunk/dsim/test/boost/intrusive/BomRoot.hpp 2010-09-11 16:51:17 UTC (rev 130)
@@ -0,0 +1,23 @@
+#ifndef __INTRUSIVE_BOM_BOMROOT_HPP
+#define __INTRUSIVE_BOM_BOMROOT_HPP
+
+// //////////////////////////////////////////////////////////////////////
+// Import section
+// //////////////////////////////////////////////////////////////////////
+// STL
+#include <cassert>
+#include <string>
+//
+#include <test/boost/intrusive/BomAbstract.hpp>
+
+namespace intrusive {
+
+ /** BomRoot. */
+ class BomRoot : public BomAbstract {
+ public:
+ BomRoot (const std::string& iKey) : BomAbstract (iKey) {}
+ BomRoot (const int idx) : BomAbstract (idx) {}
+ };
+
+}
+#endif // __INTRUSIVE_BOM_BOMROOT_HPP
Added: trunk/dsim/test/boost/intrusive/FlightDate.hpp
===================================================================
--- trunk/dsim/test/boost/intrusive/FlightDate.hpp (rev 0)
+++ trunk/dsim/test/boost/intrusive/FlightDate.hpp 2010-09-11 16:51:17 UTC (rev 130)
@@ -0,0 +1,33 @@
+#ifndef __INTRUSIVE_BOM_FLIGHTDATE_HPP
+#define __INTRUSIVE_BOM_FLIGHTDATE_HPP
+
+// //////////////////////////////////////////////////////////////////////
+// Import section
+// //////////////////////////////////////////////////////////////////////
+// STL
+#include <cassert>
+#include <string>
+// Local
+#include <test/boost/intrusive/BomAbstract.hpp>
+
+/** Alias for the boost::intrusive namespace. */
+namespace bi = boost::intrusive;
+
+namespace intrusive {
+
+ /** FlightDate. */
+ class FlightDate : public BomAbstract {
+ public:
+ FlightDate (const std::string& iKey) : BomAbstract (iKey) {}
+ FlightDate (const int idx) : BomAbstract (idx) {}
+
+ bi::list_member_hook<> _childHook;
+ };
+
+ /** List of child-type FlightDate objects. */
+ typedef bi::member_hook <FlightDate, bi::list_member_hook<>,
+ &FlightDate::_childHook> FlightDateChildMemberOption;
+ typedef bi::list<FlightDate, FlightDateChildMemberOption> FlightDateChildren;
+
+}
+#endif // __INTRUSIVE_BOM_FLIGHTDATE_HPP
Added: trunk/dsim/test/boost/intrusive/LegDate.hpp
===================================================================
--- trunk/dsim/test/boost/intrusive/LegDate.hpp (rev 0)
+++ trunk/dsim/test/boost/intrusive/LegDate.hpp 2010-09-11 16:51:17 UTC (rev 130)
@@ -0,0 +1,39 @@
+#ifndef __INTRUSIVE_BOM_LEGDATE_HPP
+#define __INTRUSIVE_BOM_LEGDATE_HPP
+
+// //////////////////////////////////////////////////////////////////////
+// Import section
+// //////////////////////////////////////////////////////////////////////
+// STL
+#include <cassert>
+#include <string>
+//
+#include <test/boost/intrusive/BomAbstract.hpp>
+
+/** Alias for the boost::intrusive namespace. */
+namespace bi = boost::intrusive;
+
+namespace intrusive {
+
+ /** LegDate. */
+ class LegDate : public BomAbstract {
+ public:
+ LegDate (const std::string& iKey) : BomAbstract (iKey) {}
+ LegDate (const int idx) : BomAbstract (idx) {}
+
+ bi::list_member_hook<> _childHook;
+ bi::list_member_hook<> _siblingHook;
+ };
+
+ /** 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
Modified: trunk/dsim/test/boost/intrusive/Makefile.am
===================================================================
--- trunk/dsim/test/boost/intrusive/Makefile.am 2010-09-11 15:42:49 UTC (rev 129)
+++ trunk/dsim/test/boost/intrusive/Makefile.am 2010-09-11 16:51:17 UTC (rev 130)
@@ -1,5 +1,6 @@
## test/boost/intrusive sub-directory
include $(top_srcdir)/Makefile.common
+include $(srcdir)/sources.mk
MAINTAINERCLEANFILES = Makefile.in
@@ -9,12 +10,17 @@
EXTRA_DIST =
##
-check_PROGRAMS = intrusive
+check_PROGRAMS = intrusive bom
#TESTS = $(check_PROGRAMS)
TESTS =
XFAIL_TESTS = #IndexBuildingTestSuite
intrusive_SOURCES = intrusive.cpp
-intrusive_CXXFLAGS= $(BOOST_CFLAGS)
+intrusive_CXXFLAGS = $(BOOST_CFLAGS)
intrusive_LDFLAGS = $(BOOST_LIBS)
intrusive_LDADD =
+
+bom_SOURCES = $(intru_bom_h_sources) $(intru_bom_cc_sources)
+bom_CXXFLAGS = $(BOOST_CFLAGS)
+bom_LDFLAGS = $(BOOST_LIBS)
+bom_LDADD =
Added: trunk/dsim/test/boost/intrusive/SegmentDate.hpp
===================================================================
--- trunk/dsim/test/boost/intrusive/SegmentDate.hpp (rev 0)
+++ trunk/dsim/test/boost/intrusive/SegmentDate.hpp 2010-09-11 16:51:17 UTC (rev 130)
@@ -0,0 +1,41 @@
+#ifndef __INTRUSIVE_BOM_SEGMENTDATE_HPP
+#define __INTRUSIVE_BOM_SEGMENTDATE_HPP
+
+// //////////////////////////////////////////////////////////////////////
+// Import section
+// //////////////////////////////////////////////////////////////////////
+// STL
+#include <cassert>
+#include <string>
+//
+#include <test/boost/intrusive/BomAbstract.hpp>
+
+/** Alias for the boost::intrusive namespace. */
+namespace bi = boost::intrusive;
+
+namespace intrusive {
+
+ /** SegmentDate. */
+ class SegmentDate : public BomAbstract {
+ public:
+ SegmentDate (const std::string& iKey) : BomAbstract (iKey) {}
+ SegmentDate (const int idx) : BomAbstract (idx) {}
+
+ bi::list_member_hook<> _childHook;
+ bi::list_member_hook<> _siblingHook;
+ };
+
+ /** 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
Copied: trunk/dsim/test/boost/intrusive/bom.cpp (from rev 129, trunk/dsim/test/boost/intrusive/intrusive.cpp)
===================================================================
--- trunk/dsim/test/boost/intrusive/bom.cpp (rev 0)
+++ trunk/dsim/test/boost/intrusive/bom.cpp 2010-09-11 16:51:17 UTC (rev 130)
@@ -0,0 +1,49 @@
+// STL
+#include <cassert>
+#include <sstream>
+#include <string>
+#include <vector>
+// Boost
+#include <boost/intrusive/list.hpp>
+// Local
+#include <test/boost/intrusive/FlightDate.hpp>
+
+/** Alias for the boost::intrusive namespace. */
+namespace bi = boost::intrusive;
+
+
+
+// /////////////////////////// M A I N /////////////////////////
+int main (int argc, char* argv[]) {
+
+ // Create several FlightDate objects, each one with a different value
+ std::vector<intrusive::FlightDate> flightDateList;
+ for (int i = 0; i < 100; ++i) {
+ flightDateList.push_back (intrusive::FlightDate (i));
+ }
+
+ intrusive::FlightDateChildren flightDateChildren;
+
+ // Now insert them in the same order as in vector in the member hook list
+ for (std::vector<intrusive::FlightDate>::iterator it (flightDateList.begin()),
+ itend (flightDateList.end()); it != itend; ++it) {
+ flightDateChildren.push_back (*it);
+ }
+
+ // Now test lists
+ {
+ intrusive::FlightDateChildren::iterator mit (flightDateChildren.begin()),
+ mitend (flightDateChildren.end());
+ std::vector<intrusive::FlightDate>::iterator it (flightDateList.begin()),
+ itend (flightDateList.end());
+
+ // Test the objects inserted in the member hook list
+ for (it = flightDateList.begin(); it != itend; ++it, ++mit) {
+ if (&*mit != &*it) {
+ return 1;
+ }
+ }
+ }
+
+ return 0;
+}
Added: trunk/dsim/test/boost/intrusive/sources.mk
===================================================================
--- trunk/dsim/test/boost/intrusive/sources.mk (rev 0)
+++ trunk/dsim/test/boost/intrusive/sources.mk 2010-09-11 16:51:17 UTC (rev 130)
@@ -0,0 +1,8 @@
+intru_bom_h_sources = \
+ $(top_srcdir)/test/boost/intrusive/BomAbstract.hpp \
+ $(top_srcdir)/test/boost/intrusive/BomRoot.hpp \
+ $(top_srcdir)/test/boost/intrusive/FlightDate.hpp \
+ $(top_srcdir)/test/boost/intrusive/LegDate.hpp \
+ $(top_srcdir)/test/boost/intrusive/SegmentDate.hpp
+intru_bom_cc_sources = \
+ $(top_srcdir)/test/boost/intrusive/bom.cpp
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|