|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r83084 - sandbox/icl/libs/xplore/value_sem/TreeSync1/TreeSync1
From: afojgo_at_[hidden]
Date: 2013-02-22 11:43:39
Author: jofaber
Date: 2013-02-22 11:43:38 EST (Fri, 22 Feb 2013)
New Revision: 83084
URL: http://svn.boost.org/trac/boost/changeset/83084
Log:
Merge Tree.
Text files modified:
sandbox/icl/libs/xplore/value_sem/TreeSync1/TreeSync1/Object.h | 8 ++++
sandbox/icl/libs/xplore/value_sem/TreeSync1/TreeSync1/Tree.h | 74 ++++++++++++++++++++++++++++++++-------
sandbox/icl/libs/xplore/value_sem/TreeSync1/TreeSync1/TreeSync1.cpp | 42 +++++++++++++++-------
3 files changed, 96 insertions(+), 28 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-22 11:43:38 EST (Fri, 22 Feb 2013)
@@ -2,6 +2,7 @@
#include <string>
#include <iostream>
+#include <typeinfo>
#include <boost/smart_ptr/shared_ptr.hpp>
template<class T>
@@ -26,12 +27,15 @@
x.m_object->draw_(out, pos);
}
+ friend std::string type_name(const object& x){ return x.m_object->type_name_(); }
+
private:
struct concept
{
virtual ~concept() {}
virtual concept* copy() = 0;
virtual void draw_(std::ostream&, size_t)const = 0;
+ virtual std::string type_name_()const = 0;
};
template<class Model> struct model : concept
@@ -40,9 +44,13 @@
concept* copy(){ return new model(*this); }
void draw_(std::ostream& out, size_t pos)const
{
+ //out << std::string(pos, ' ') << "{ " << type_name() << " }";
draw(m_model, out, pos);
}
+ //std::string type_name()const { return typeid(m_model).name(); }
+ std::string type_name_()const{ return type_name(m_model); }
+
Model m_model;
};
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-22 11:43:38 EST (Fri, 22 Feb 2013)
@@ -7,7 +7,8 @@
typedef int tUuid;
typedef int tTime;
-template<class Uuid>
+
+template<class Uuid, class Time = int>
class Playable
{
public:
@@ -16,6 +17,7 @@
{ }
Uuid uuid()const { return m_uuid; }
+ Time time()const { return Time(); } //JODO
private:
Uuid m_uuid;
@@ -28,11 +30,8 @@
return stream << "Play(" << object.uuid() << ")";
}
-typedef std::vector<Playable<tUuid> > tPlaylist;
-
-struct PlayableTag{};
-template<class Type>
+template<class Type, class Uuid = int, class Time = int>
struct Vec
{
typedef std::vector<object> tVector;
@@ -40,17 +39,35 @@
typedef tVector::const_iterator const_iterator;
typedef tVector::value_type value_type;
+ Vec(): m_uuid(), m_time(), m_name(), m_vector() {}
+ Vec(Uuid const& uuid, Time const& time, std::string const& name)
+ : m_uuid(uuid), m_time(time), m_name(name), m_vector() {}
+
const_iterator begin()const { return m_vector.begin(); }
const_iterator end()const { return m_vector.end(); }
- void push_back(const Type& val){ m_vector.push_back(val); }
+ void push_back(const Type& val)
+ {
+ m_time = std::max(m_time, val.time());
+ m_vector.push_back(val);
+ }
+
+ Uuid uuid()const { return m_uuid; }
+ Time time()const { return m_time; }
+ std::string name()const { return m_name; }
+
+ void setUuid(Uuid const& uuid){ m_uuid = uuid; }
+ void setTime(Time const& time){ m_time = time; }
+ void name(std::string const& name)const { m_name = name; }
+ Uuid m_uuid;
+ Time m_time;
+ std::string m_name;
tVector m_vector;
};
-
-template<class Content>
+template<class Content, class Uuid = int, class Time = int>
class Node
{
public:
@@ -58,22 +75,33 @@
typedef Vec<Node> NodeVec;
- Node(const ContentVec& content = ContentVec(), const NodeVec& children = NodeVec())
- : m_content(content), m_children(children)
- { }
+ Node( Uuid const& uuid = 0, std::string const& name = std::string()
+ , const ContentVec& content = ContentVec(), const NodeVec& children = NodeVec())
+ : m_uuid(uuid), m_name(name)
+ , m_content(content), m_children(children)
+ {
+ m_time = std::max(m_content.time(), m_children.time());
+ }
+
+ Uuid uuid()const { return m_uuid; }
+ Time time()const { return m_time; }
+ std::string name()const { return m_name; }
ContentVec content()const { return m_content; }
NodeVec children()const { return m_children; }
private:
- ContentVec m_content;
- NodeVec m_children;
+ Uuid m_uuid;
+ Time m_time;
+ std::string m_name;
+ ContentVec m_content;
+ NodeVec m_children;
};
template<class Type>
void draw(const Node<Type>& obj, std::ostream& out, size_t pos)
{
- out << std::string(pos,' ') << "<Node>\n";
+ out << std::string(pos,' ') << "<Node>[" << obj.name() << "](" << obj.uuid() << "," << obj.time() <<")\n";
draw(obj.content(), out, pos+2);
draw(obj.children(), out, pos+2);
@@ -81,3 +109,21 @@
out << std::string(pos,' ') << "</Node>\n";
}
+/*
+template<class Type>
+Node<Type> merge(const Node<Type>& lhs, const Node<Type>& rhs)
+{
+ Node<Type> merged;
+ m_uuid = lhs.uuid();
+ m_time = std::max(lhs.time(), rhs.time());
+
+ for( ContentVec::const_iterator cont_it = m_content.begin()
+ ; cont_it != m_content.end(); ++ cont_it)
+ {
+ merged.push_back(merge(*cont_it), );
+ }
+ merged.setContent(merge_content(lhs, rhs));
+ merged.setChildren(merge_children(lhs, rhs));
+}
+*/
+
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-22 11:43:38 EST (Fri, 22 Feb 2013)
@@ -16,6 +16,12 @@
typedef Vec<Node<Playlist> > NodeList;
+template<class Type>
+std::string type_name(Type const& value)
+{
+ return typeid(value).name();
+}
+
void draw(const int& val, std::ostream& out, size_t pos)
{
out << std::string(pos, ' ') << "int: " << val << std::endl;
@@ -36,13 +42,17 @@
}
template<class Type>
-void draw(const Vec<Type>& col, std::ostream& out, size_t pos)
+void draw(const Vec<Type>& obj, std::ostream& out, size_t pos)
{
- out << std::string(pos,' ') << "<Vec>\n";
- for(coll_citer it = col.begin(); it != col.end(); ++it)
+ out << std::string(pos,' ')
+ //<< type_name(obj) << "{\n";
+ << "<Vec>[" << obj.name() << "](" << obj.uuid() << "," << obj.time() << ")\n";
+ for(coll_citer it = obj.begin(); it != obj.end(); ++it)
draw(*it, out, pos+2);
- out << std::string(pos,' ') << "</Vec>\n";
+ out << std::string(pos,' ')
+ //<< "}\n";
+ << "</Vec>\n";
}
int _tmain(int argc, _TCHAR* argv[])
@@ -51,28 +61,32 @@
collection coll;
- Playlist pl1;
+ coll.push_back(42);
+
+ Playlist pl1(1, 2, " pl_1 ");
pl1.push_back(Playable<int>(43));
pl1.push_back(Playable<int>(44));
- Playlist pl2;
+ Playlist pl2(2, 4, " pl_2 ");
pl2.push_back(Playable<int>(53));
pl2.push_back(Playable<int>(54));
//draw(pl, std::cout, 0);
- Playlists pls1;
+
+ Playlists pls1(3, 3, " pls_1 ");
pls1.push_back(pl1);
- Playlists pls2;
+ Playlists pls2(4, 3, " pls_1 ");
pls2.push_back(pl2);
- Node<Playlist> node1(pls1);
- NodeList nodes1;
+ Node<Playlist> node1(5, " node_1 ", pls1);
+ NodeList nodes1(5, 2, " nodes_1 ");
nodes1.push_back(node1);
- Node<Playlist> node2(pls2, nodes1);
+
+ Node<Playlist> node2(6, " node_2 ", pls2, nodes1);
- coll.push_back(node1);
- coll.push_back(node2);
- draw(coll, std::cout, 0);
+ //coll.push_back(node1);
+ //coll.push_back(node2);
+ draw(node2, std::cout, 0);
return 0;
}
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