Omnidome
Fulldome Mapping Software Toolkit
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Id.h
Go to the documentation of this file.
1 /* Copyright (c) 2014-2015 "Omnidome" by cr8tr
2  * Dome Mapping Projection Software (http://omnido.me).
3  * Omnidome was created by Michael Winkelmann aka Wilston Oreo (@WilstonOreo)
4  *
5  * This file is part of Omnidome.
6  *
7  * Omnidome is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU Affero General Public License for more details.
16  * You should have received a copy of the GNU Affero General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef OMNI_ID_H_
21 #define OMNI_ID_H_
22 
23 #include <set>
24 #include <QString>
25 #include <QDataStream>
26 #include <boostx/type_info.hpp>
27 #include <boostx/factory.hpp>
28 
29 namespace omni {
30  /**@brief Id type for classes
31  * @detail An Id must only contain alpha numerical characters
32  * and must begin with a letter
33  **/
34  struct Id
35  {
36  /// Default constructor
37  Id();
38 
39  /// Constructor from string
40  Id(QString const&);
41 
42  /// Constructor from const char*
43  Id(const char *);
44 
45  /// Returns string representation (const)
46  QString const& str() const;
47 
48  /// Cast operator returns copy of string representation
49  operator QString() const;
50 
51  /// Returns true if string is valid
52  bool valid() const;
53 
54  /// Comparison operator
55  bool operator<(const Id&) const;
56 
57  /// Returns true if two ids do not match
58  bool operator!=(const Id&) const;
59 
60  /// Returns true if two ids match
61  bool operator==(const Id&) const;
62 
63  private:
64  /// Make Id from string
65  void make(QString const&);
66 
67  /// Internal string buffer
68  QString str_;
69  };
70 
72  TypeInfo,
73  Id,
74  typeId,
75  getTypeId
76  )
77 
78  /// Alias template for factories
79  template<typename INTERFACE, typename ... ARGS>
80  using AbstractFactory = boostx::factory<INTERFACE, TypeInfo, ARGS ...>;
81 
82  /// Id set typedef
83  typedef std::set<Id>IdSet;
84 }
85 
86 namespace std {
87  /// Template specialization for Id to make it hashable
88  template<>
89  struct hash<omni::Id>
90  {
91  /// Use hash<std::string> to produce hash value
92  inline size_t operator()(const omni::Id& _id) const
93  {
94  return hash<std::string>()(_id.str().toStdString());
95  }
96  };
97 }
98 
99 
100 /// Serialize omni::Id to stream
101 QDataStream& operator<<(QDataStream&,
102  omni::Id const&);
103 
104 /// Deserialize omni::Id from stream
105 QDataStream& operator>>(QDataStream&,
106  omni::Id&);
107 
108 #endif /* OMNI_ID_H_ */
BOOSTX_DECL_TYPE_INFO(TypeInfo, Id, typeId, getTypeId) template< typename INTERFACE
Alias template for factories.
Id type for classes An Id must only contain alpha numerical characters and must begin with a letter...
Definition: Id.h:34
QString const & str() const
Returns string representation (const)
Definition: Id.cpp:42
Id()
Default constructor.
Definition: Id.cpp:28
std::set< Id > IdSet
Id set typedef.
Definition: Id.h:83
size_t operator()(const omni::Id &_id) const
Use hash<std::string> to produce hash value.
Definition: Id.h:92
QDataStream & operator>>(QDataStream &, omni::Id &)
Deserialize omni::Id from stream.
Definition: Id.cpp:97
bool operator<(const Id &) const
Comparison operator.
Definition: Id.cpp:57
bool valid() const
Returns true if string is valid.
Definition: Id.cpp:52
void make(QString const &)
Make Id from string.
Definition: Id.cpp:72
bool operator!=(const Id &) const
Returns true if two ids do not match.
Definition: Id.cpp:62
QDataStream & operator<<(QDataStream &, omni::Id const &)
Serialize omni::Id to stream.
Definition: Id.cpp:91
bool operator==(const Id &) const
Returns true if two ids match.
Definition: Id.cpp:67
QString str_
Internal string buffer.
Definition: Id.h:68
The central factory class.
Definition: factory.hpp:38