|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r83174 - sandbox/icl/libs/xplore/value_sem/TreeSync1/TreeSync1
From: afojgo_at_[hidden]
Date: 2013-02-26 18:42:49
Author: jofaber
Date: 2013-02-26 18:42:48 EST (Tue, 26 Feb 2013)
New Revision: 83174
URL: http://svn.boost.org/trac/boost/changeset/83174
Log:
Added Syncable_ModeledBy
Text files modified:
sandbox/icl/libs/xplore/value_sem/TreeSync1/TreeSync1/Object.h | 4
sandbox/icl/libs/xplore/value_sem/TreeSync1/TreeSync1/Tree.h | 104 +++++++++++++++++++++++++++++++++++++--
sandbox/icl/libs/xplore/value_sem/TreeSync1/TreeSync1/TreeSync1.cpp | 11 ++-
sandbox/icl/libs/xplore/value_sem/TreeSync1/TreeSync1/TreeSync1.vcproj | 2
4 files changed, 107 insertions(+), 14 deletions(-)
Modified: sandbox/icl/libs/xplore/value_sem/TreeSync1/TreeSync1/Object.h
==============================================================================
--- sandbox/icl/libs/xplore/value_sem/TreeSync1/TreeSync1/Object.h (original)
+++ sandbox/icl/libs/xplore/value_sem/TreeSync1/TreeSync1/Object.h 2013-02-26 18:42:48 EST (Tue, 26 Feb 2013)
@@ -58,8 +58,8 @@
bool is_less_(concept const& rhs)const
{
- //return is_less(m_model, dynamic_cast<model const&>(rhs).m_model);
- return m_model < dynamic_cast<model const&>(rhs).m_model;
+ //return is_less(m_model, dynamic_cast<model const&>(rhs).m_model);
+ return m_model < dynamic_cast<model const&>(rhs).m_model;
}
void draw_(std::ostream& out, size_t pos)const
Modified: sandbox/icl/libs/xplore/value_sem/TreeSync1/TreeSync1/Tree.h
==============================================================================
--- sandbox/icl/libs/xplore/value_sem/TreeSync1/TreeSync1/Tree.h (original)
+++ sandbox/icl/libs/xplore/value_sem/TreeSync1/TreeSync1/Tree.h 2013-02-26 18:42:48 EST (Tue, 26 Feb 2013)
@@ -1,13 +1,17 @@
#pragma once
#include <ostream>
+#include <iterator>
#include <vector>
+#include <boost/utility/enable_if.hpp>
#include "std_algorithm.h"
#include "Object.h"
typedef int tUuid;
typedef int tTime;
+template<class ContentT, class UuidT = int, class TimeT = int>
+class Node;
template<class Uuid, class Time = int>
class Playable
@@ -61,10 +65,12 @@
}
-template<class Type, class Uuid = int, class Time = int>
+template<class Type, class UuidT = int, class TimeT = int>
struct Vec
{
- typedef std::vector<Type> tVector;
+ typedef std::vector<Type> tVector;
+ typedef UuidT Uuid;
+ typedef TimeT Time;
typedef typename tVector::size_type size_type;
typedef typename tVector::value_type value_type;
@@ -141,11 +147,97 @@
return lhs.time() < rhs.time();
}
-template<class Content, class Uuid = int, class Time = int>
+//-----------------------------------------------------------------
+// Concept Dateable something that is universally identifiable
+// and has a timestamp, so it can be synchronized
+template<class ModelT> struct Syncable_ModeledBy
+{
+ static const bool value = false;
+ typedef typename ModelT Model;
+ typedef typename Model::Uuid Uuid;
+ typedef typename Model::Time Time;
+ static Uuid uuid(Model const&);
+ static Time time(Model const&);
+};
+
+template<class UuidT, class TimeT>
+struct Syncable_ModeledBy<Playable<UuidT,TimeT> >
+{
+ static const bool value = true;
+ typedef typename Playable<UuidT> Model;
+ typedef typename Model::Uuid Uuid;
+ typedef typename Model::Time Time;
+ static Uuid uuid(Model const& object){ return object.uuid() };
+ static Time time(Model const& object){ return object.time() };
+};
+
+template<class ElementT, class UuidT, class TimeT>
+struct Syncable_ModeledBy<Vec<ElementT,UuidT,TimeT> >
+{
+ static const bool value = true;
+ typedef typename Vec<ElementT,UuidT,TimeT> Model;
+ typedef typename Model::Uuid Uuid;
+ typedef typename Model::Time Time;
+ static Uuid uuid(Model const& object){ return object.uuid(); }
+ static Time time(Model const& object){ return object.time(); }
+};
+
+template<class ContentT,class UuidT, class TimeT>
+struct Syncable_ModeledBy<Node<ContentT,UuidT,TimeT> >
+{
+ static const bool value = true;
+ typedef typename Node<ContentT,UuidT,TimeT> Model;
+ typedef typename Model::Uuid Uuid;
+ typedef typename Model::Time Time;
+ static Uuid uuid(Model const& object){ return object.uuid(); }
+ static Time time(Model const& object){ return object.time(); }
+};
+
+template<class Model>
+typename boost::enable_if<Syncable_ModeledBy<Model>,
+typename Syncable_ModeledBy<Model>::Uuid>::type uuid(Model const& object)
+{
+ return Syncable_ModeledBy<Model>::uuid(object);
+}
+
+template<class Model>
+typename boost::enable_if<Syncable_ModeledBy<Model>,
+typename Syncable_ModeledBy<Model>::Time>::type time(Model const& object)
+{
+ return Syncable_ModeledBy<Model>::time(object);
+}
+
+template<class Model>
+typename boost::enable_if<Syncable_ModeledBy<Model>,
+bool>::type less_for_time(Model const& lhs, Model const& rhs)
+{
+ return time(lhs) < time(rhs);
+}
+
+template<class Model>
+typename boost::enable_if<Syncable_ModeledBy<Model>,
+bool>::type less_for_uuid(Model const& lhs, Model const& rhs)
+{
+ return uuid(lhs) < uuid(rhs);
+}
+
+template<class Syncable>
+struct LessForUuid : std::binary_function<Syncable const&, Syncable const&, bool>
+{
+ bool operator()(Syncable const& lhs, Syncable const& rhs)
+ { return less_for_uuid(lhs, rhs); }
+};
+
+
+//-----------------------------------------------------------------
+
+template<class ContentT, class UuidT = int, class TimeT = int>
class Node
{
public:
- typedef Content ContentType;
+ typedef ContentT Content;
+ typedef UuidT Uuid;
+ typedef TimeT Time;
typedef Vec<Content> ContentVec;
typedef Vec<Node> NodeVec;
@@ -288,13 +380,13 @@
template<class Type>
void sortElements(Node<Type>& val)
{
- std::sort( val.elements_begin(), val.elements_end());
+ std::sort( val.elements_begin(), val.elements_end(), LessForUuid<Type>());
}
template<class Type>
void sortNodes(Node<Type>& val)
{
- std::sort( val.nodes_begin(), val.nodes_end());
+ std::sort( val.nodes_begin(), val.nodes_end(), LessForUuid<Node<Type> >());
std::for_each(val.nodes_begin(), val.nodes_end(), Sorter<Node<Type> >());
}
Modified: sandbox/icl/libs/xplore/value_sem/TreeSync1/TreeSync1/TreeSync1.cpp
==============================================================================
--- sandbox/icl/libs/xplore/value_sem/TreeSync1/TreeSync1/TreeSync1.cpp (original)
+++ sandbox/icl/libs/xplore/value_sem/TreeSync1/TreeSync1/TreeSync1.cpp 2013-02-26 18:42:48 EST (Tue, 26 Feb 2013)
@@ -65,24 +65,25 @@
coll.push_back(42);
//--- Playlist --------------------
- Playlist pl1(1, 2, " pl_1 ");
+ Playlist pl1(3, 2, " pl_1 ");
pl1.push_back(Playable<int>(11));
- pl1.push_back(Playable<int>(12));
+ pl1.push_back(Playable<int>(10));
Playlist pl2(2, 5, " pl_2 ");
pl2.push_back(Playable<int>(21));
- pl2.push_back(Playable<int>(22));
+ pl2.push_back(Playable<int>(20));
- Playlist pl3(3, 3, " pl_3 ");
+ Playlist pl3(1, 3, " pl_3 ");
pl2.push_back(Playable<int>(31));
//--- Playlists -------------------
Playlists pls1(4, 0, " pls_1 ");
pls1.push_back(pl1);
+ pls1.push_back(pl2);
pls1.push_back(pl3);
- Playlists pls2(5, 0, " pls_1 ");
+ Playlists pls2(5, 0, " pls_2 ");
pls2.push_back(pl2);
pls2.push_back(pl3);
Modified: sandbox/icl/libs/xplore/value_sem/TreeSync1/TreeSync1/TreeSync1.vcproj
==============================================================================
--- sandbox/icl/libs/xplore/value_sem/TreeSync1/TreeSync1/TreeSync1.vcproj (original)
+++ sandbox/icl/libs/xplore/value_sem/TreeSync1/TreeSync1/TreeSync1.vcproj 2013-02-26 18:42:48 EST (Tue, 26 Feb 2013)
@@ -41,7 +41,7 @@
<Tool
Name="VCCLCompilerTool"
Optimization="0"
- AdditionalIncludeDirectories="C:\NIBuild\3rdparty\boost-1.51.0-R4"
+ AdditionalIncludeDirectories="C:\NIBuild\3rdparty\boost-1.51.0-R4; C:\cygwin\home\jofa\dev\boost\trunk"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
MinimalRebuild="true"
BasicRuntimeChecks="3"
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