DUDS
Distributed Update of Data from Something
Something.hpp
Go to the documentation of this file.
1 /*
2  * This file is part of the DUDS project. It is subject to the BSD-style
3  * license terms in the LICENSE file found in the top-level directory of this
4  * distribution and at https://github.com/jjackowski/duds/blob/master/LICENSE.
5  * No part of DUDS, including this file, may be copied, modified, propagated,
6  * or distributed except according to the terms contained in the LICENSE file.
7  *
8  * Copyright (C) 2017 Jeff Jackowski
9  */
10 #ifndef SOMETHING_HPP
11 #define SOMETHING_HPP
12 
13 #include <boost/uuid/uuid.hpp>
15 #include <boost/noncopyable.hpp>
16 #include <memory>
17 
18 namespace duds {
19 
26 class Something :
27 public std::enable_shared_from_this<Something>, boost::noncopyable
28 {
32  boost::uuids::uuid someId;
33 protected:
42  Something() = default;
47  Something(const boost::uuids::uuid &id) : someId(id) { }
54  void setUuid(const boost::uuids::uuid &id) {
55  someId = id;
56  }
57 public:
58  virtual ~Something() = 0;
65  template <class DerivedClass>
66  std::shared_ptr<DerivedClass> sharedPtr() const {
67  return std::static_pointer_cast<DerivedClass>(shared_from_this());
68  }
72  const boost::uuids::uuid &uuid() const {
73  return someId;
74  }
79  return ltnames;
80  }
85  std::string getName() const;
89  bool operator < (const Something &s) const {
90  return someId < s.someId;
91  }
95  bool operator > (const Something &s) const {
96  return someId > s.someId;
97  }
101  bool operator <= (const Something &s) const {
102  return someId <= s.someId;
103  }
107  bool operator >= (const Something &s) const {
108  return someId >= s.someId;
109  }
113  bool operator == (const Something &s) const {
114  return someId == s.someId;
115  }
119  bool operator != (const Something &s) const {
120  return someId != s.someId;
121  }
122 };
123 
124 typedef std::shared_ptr<Something> SomethingSptr;
125 typedef std::weak_ptr<Something> SomethingWptr;
126 
127 }
128 
129 #endif // #ifndef SOMETHING_HPP
std::shared_ptr< DerivedClass > sharedPtr() const
Returns a shared pointer to this object for a derived class.
Definition: Something.hpp:66
boost::uuids::uuid someId
A unique identifier that is valid across all peers.
Definition: Something.hpp:32
bool operator!=(const Something &s) const
Something objects are compared using the someId member.
Definition: Something.hpp:119
std::weak_ptr< Something > SomethingWptr
Definition: Something.hpp:125
bool operator==(const Something &s) const
Something objects are compared using the someId member.
Definition: Something.hpp:113
Something(const boost::uuids::uuid &id)
Creates Something with the given UUID.
Definition: Something.hpp:47
Something specific; a base class for identifying things.
Definition: Something.hpp:26
bool operator>(const Something &s) const
Something objects are compared using the someId member.
Definition: Something.hpp:95
bool operator>=(const Something &s) const
Something objects are compared using the someId member.
Definition: Something.hpp:107
const boost::uuids::uuid & uuid() const
Returns the object&#39;s unique identifier.
Definition: Something.hpp:72
std::map< std::string, std::string > LanguageTaggedStringMap
std::string getName() const
Returns the name for the current locale.
bool operator<=(const Something &s) const
Something objects are compared using the someId member.
Definition: Something.hpp:101
virtual ~Something()=0
Definition: Something.cpp:5
const general::LanguageTaggedStringMap & names() const
Returns the set of names for all locales and languages.
Definition: Something.hpp:78
bool operator<(const Something &s) const
Something objects are compared using the someId member.
Definition: Something.hpp:89
Something()=default
Simple constructor.
general::LanguageTaggedStringMap ltnames
A name for this item intended for user presentation.
Definition: Something.hpp:37
void setUuid(const boost::uuids::uuid &id)
Sets the UUID that is associated with this object.
Definition: Something.hpp:54
std::shared_ptr< Something > SomethingSptr
Definition: Something.hpp:124