Update of /cvsroot/boost/boost/libs/intrusive/example
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv27901/example
Modified Files:
doc_offset_ptr.cpp doc_value_traits.cpp
Added Files:
doc_advanced_value_traits2.cpp
Log Message:
New Intrusive version
--- NEW FILE: doc_advanced_value_traits2.cpp ---
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2006-2007
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
#include <boost/intrusive/linking_policy.hpp>
#include <boost/intrusive/list.hpp>
#include <boost/intrusive/member_value_traits.hpp>
#include <vector>
struct simple_node
{
simple_node *prev_;
simple_node *next_;
};
//Define the node traits. A single node_traits will be enough.
struct simple_node_traits
{
typedef simple_node node;
typedef node * node_ptr;
typedef const node * const_node_ptr;
static node *get_next(const node *n) { return n->next_; }
static void set_next(node *n, node *next) { n->next_ = next; }
static node *get_previous(const node *n) { return n->prev_; }
static void set_previous(node *n, node *prev) { n->prev_ = prev; }
};
//[doc_advanced_value_traits2_value_traits
class base_1{};
class base_2{};
struct value_1 : public base_1, public simple_node
{
int id_;
simple_node node_;
};
struct value_2 : public base_1, public base_2, public simple_node
{
simple_node node_;
float id_;
};
using namespace boost::intrusive;
typedef member_value_traits
<value_1, simple_node_traits, &value_1::node_, normal_link> ValueTraits1;
typedef member_value_traits
<value_2, simple_node_traits, &value_2::node_, normal_link> ValueTraits2;
//Now define two intrusive lists. Both lists will use the same algorithms:
// circular_list_algorithms<simple_node_traits>
typedef boost::intrusive::list <ValueTraits1> Value1List;
typedef boost::intrusive::list <ValueTraits2> Value2List;
//]
//[doc_advanced_value_traits2_test
int main()
{
typedef std::vector<value_1> Vect1;
typedef std::vector<value_2> Vect2;
//Create values, with a different internal number
Vect1 values1;
Vect2 values2;
for(int i = 0; i < 100; ++i){
value_1 v1; v1.id_ = i; values1.push_back(v1);
value_2 v2; v2.id_ = (float)i; values2.push_back(v2);
}
//Create the lists with the objects
Value1List list1(values1.begin(), values1.end());
Value2List list2(values2.begin(), values2.end());
//Now test both lists
Value1List::const_iterator bit1(list1.begin()), bitend1(list1.end());
Value2List::const_iterator bit2(list2.begin()), bitend2(list2.end());
Vect1::const_iterator it1(values1.begin()), itend1(values1.end());
Vect2::const_iterator it2(values2.begin()), itend2(values2.end());
//Test the objects inserted in our lists
for(; it1 != itend1; ++it1, ++bit1, ++it2, ++bit2){
if(&*bit1 != &*it1 || &*bit2 != &*it2) return false;
}
return 0;
}
//]
Index: doc_offset_ptr.cpp
===================================================================
RCS file: /cvsroot/boost/boost/libs/intrusive/example/doc_offset_ptr.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- doc_offset_ptr.cpp 24 May 2007 05:01:18 -0000 1.3
+++ doc_offset_ptr.cpp 22 Jul 2007 14:19:19 -0000 1.4
@@ -45,7 +45,7 @@
//nodes and the container itself must be created in shared memory
const int MaxElem = 100;
const int ShmSize = 50000;
- const char *ShmName = "MySharedMemory";
+ const char *ShmName = "SharedMemoryName";
using namespace boost::interprocess;
Index: doc_value_traits.cpp
===================================================================
RCS file: /cvsroot/boost/boost/libs/intrusive/example/doc_value_traits.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- doc_value_traits.cpp 12 May 2007 12:34:55 -0000 1.2
+++ doc_value_traits.cpp 22 Jul 2007 14:19:19 -0000 1.3
@@ -60,6 +60,7 @@
static pointer to_value_ptr(node_ptr n) { return
pointer(n); }
static const_pointer to_value_ptr(const_node_ptr n) { return
const_pointer(n); }
};
+
//]
//[doc_value_traits_test
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Boost-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/boost-cvs