14 #include <Mangling.hpp>
16 #include <UnorderedMap.hpp>
32 typedef intptr_t vertex_identity_t;
37 extern mgx_EXPORT
size_t vertex_counter;
39 template <
typename VertexContent,
typename Alloc>
class WeakVertex;
57 template <
typename VertexContent,
typename Alloc>
class Vertex {
68 , num(vertex_counter++)
76 , num(vertex_counter++)
82 , num(vertex_counter++)
88 typedef typename Alloc::template rebind<CountedContent>::other alloc_t;
107 cc->~CountedContent();
108 alloc.deallocate(cc, 1);
228 return id() == other.
id();
236 return id() != other.
id();
244 return id() > other.
id();
252 return id() < other.
id();
260 return id() >= other.
id();
268 return id() <= other.
id();
363 template <
typename VertexContent,
typename Alloc>
368 template <
typename VertexContent,
typename Alloc>
class WeakVertex :
public Vertex<VertexContent, Alloc> {
399 :
Vertex<VertexContent, Alloc>(0)
407 :
Vertex<VertexContent, Alloc>(0)
416 :
Vertex<VertexContent, Alloc>(0)
425 :
Vertex<VertexContent, Alloc>(0)
443 this->
content =
reinterpret_cast<CountedContent*
>(
id);
457 bool isNull()
const {
468 template <
typename VertexContent,
typename Alloc>
472 content = CountedContent::New();
475 template <
typename VertexContent,
typename Alloc>
499 template <
typename VertexContent,
typename Alloc>
501 : content(copy.content)
506 template <
typename VertexContent,
typename Alloc>
508 : content(copy.content)
513 template <
typename VertexContent,
typename Alloc>
516 if((identity_t)content ==
id)
519 content =
reinterpret_cast<CountedContent*
>(id);
524 template <
typename VertexContent,
typename Alloc>
527 const CountedContent* cid =
dynamic_cast<const CountedContent*
>(id);
529 return *
this = (
const identity_t&)cid;
531 return *
this = (
const identity_t&)(*(CountedContent::New(*
id)));
535 template <
typename VertexContent,
typename Alloc>
538 if(content == copy.content)
541 content = copy.content;
549 if(content->count == 0)
562 if(content->count == 0) {
563 CountedContent::Delete(content);
568 template <
typename VertexContent,
typename Alloc>
574 template <
typename VertexContent,
typename Alloc>
586 template <
typename VertexContent,
typename Alloc,
typename charT>
589 ss <<
"Vertex<" << util::demangle(
typeid(VertexContent).
name()) <<
">(" << v.
id() <<
")";
599 template <
typename VertexContent,
typename Alloc>
600 struct hash<mgx::graph::Vertex<VertexContent, Alloc> > {
603 return ((
size_t)v.
id()) >> 2;
607 template <
typename VertexContent,
typename Alloc>
608 struct hash<mgx::graph::WeakVertex<VertexContent, Alloc> > {
611 return ((
size_t)v.
id()) >> 2;
identity_t id() const
Return the identifier of a vertex.
Definition: Vertex.hpp:281
void release()
Release the current pointer.
Definition: Vertex.hpp:557
bool operator!=(const Vertex &other) const
Comparison operators.
Definition: Vertex.hpp:235
unsigned int count
Reference count on the vertex.
Definition: Vertex.hpp:114
bool operator==(const Vertex &other) const
Comparison operators.
Definition: Vertex.hpp:227
bool operator<(const Vertex &other) const
Comparison operators.
Definition: Vertex.hpp:251
AttribBase(const QString &name) const QString & name()
Default constructor of named attribute.
Definition: Attributes.hpp:54
Vertex< VertexContent, Alloc > strong_ref
Strong reference corresponding to the weak one.
Definition: Vertex.hpp:385
WeakVertex(const identity_t &id)
Construct a weak reference from an id.
Definition: Vertex.hpp:424
VertexContent * pointer
Type of the equivalent pointer.
Definition: Vertex.hpp:135
WeakVertex()
Construct an empty weak vertex.
Definition: Vertex.hpp:398
weak_ref_t weakRef() const
Construct a weak reference on the current vertex.
Definition: Vertex.hpp:569
Vertex()
Creates a new vertex with a new content.
Definition: Vertex.hpp:469
Type of the reference counted content.
Definition: Vertex.hpp:64
VertexContent content_t
Type of the content of the vertex.
Definition: Vertex.hpp:128
size_t num() const
Return a number unique to each vertex, globally.
Definition: Vertex.hpp:288
Definition: Vertex.hpp:39
vertex_identity_t identity_t
Type of the identifier of the vertex.
Definition: Vertex.hpp:123
vertex_identity_t identity_t
Type of the identifier of the vertex.
Definition: Vertex.hpp:375
CountedContent * content
Content of the vertex.
Definition: Vertex.hpp:350
VertexContent & operator*() const
Access to the data.
Definition: Vertex.hpp:201
VertexContent * operator->() const
Access to the data.
Definition: Vertex.hpp:193
Vertex & operator=(const Vertex &other)
Change the vertex held by the current object.
Definition: Vertex.hpp:575
void acquire()
Acquire the current pointer.
Definition: Vertex.hpp:546
bool operator<=(const Vertex &other) const
Comparison operators.
Definition: Vertex.hpp:267
Vertex of a vv graph.
Definition: Vertex.hpp:57
WeakVertex(const strong_ref &v)
Construct a weak reference from a strong one.
Definition: Vertex.hpp:406
bool isWeakRef() const
Return true if the current object hold a weak reference on a vertex.
Definition: Vertex.hpp:300
unsigned int count() const
Serialization method.
Definition: Vertex.hpp:335
VertexContent * pointer
Type of the equivalent pointer.
Definition: Vertex.hpp:390
bool operator>=(const Vertex &other) const
Comparison operators.
Definition: Vertex.hpp:259
WeakVertex & operator=(const WeakVertex &other)
Set the content of the weak reference.
Definition: Vertex.hpp:435
WeakVertex(const WeakVertex ©)
Copy constructor.
Definition: Vertex.hpp:415
bool isNull() const
Test if a vertex is a null vertex.
Definition: Vertex.hpp:274
VertexContent content_t
Type of the content of the vertex.
Definition: Vertex.hpp:380
bool operator>(const Vertex &other) const
Comparison operators.
Definition: Vertex.hpp:243
static Vertex null
Null vertex.
Definition: Vertex.hpp:325
~Vertex()
Desctructor.
Definition: Vertex.hpp:464