MeVisLab Toolbox Reference
mlObjMgrObjectID.h
Go to the documentation of this file.
1 /*************************************************************************************
2 **
3 ** Copyright 2007, MeVis Medical Solutions AG
4 **
5 ** The user may use this file in accordance with the license agreement provided with
6 ** the Software or, alternatively, in accordance with the terms contained in a
7 ** written agreement between the user and MeVis Medical Solutions AG.
8 **
9 ** For further information use the contact form at https://www.mevislab.de/contact
10 **
11 **************************************************************************************/
12 
13 #ifndef ML_OBJ_MGR_OBJECT_ID_H
14 #define ML_OBJ_MGR_OBJECT_ID_H
15 
16 
18 
19 #include "MLObjMgrSystem.h"
20 #include <mlTypeDefs.h>
21 #include <mlPrintTemplateErrors.h>
22 
23 ML_START_NAMESPACE
24 
27  template <typename T>
28  class omIDTypeT : public std::basic_string<T>
29  {
30  typedef std::basic_string<T> inherited;
31 
32  public:
33 
35  omIDTypeT() : inherited("") {}
36 
39  {
40  std::basic_ostringstream<T> o;
41  if (!(o << id)) {
42  inherited::assign("0");
43  printTemplateError("omIDType::omIDType(MLint32)", ML_BAD_DATA_TYPE, "Conversion of MLint32 to string failed (result '" + o.str() + "'). Continuing with string id '0'.");
44  }
45  else {
46  inherited::assign(o.str());
47  }
48  }
49 
51  omIDTypeT(const char *id) : inherited(id) {}
52 
54  omIDTypeT(const std::basic_string<T> &id) : inherited(id) {}
55 
57  omIDTypeT &operator =(const std::basic_string<T> &id) {
58  inherited::assign(id);
59 
60  return *this;
61  }
62 
64  operator const std::basic_string<T> &() const {
65  return *this;
66  }
67 
69  MLint32 getInt() const
70  {
71  std::basic_istringstream<T> i(*this);
72  MLint32 x=0;
73  if (!(i >> x)) {
74  x = 0;
75  printTemplateError("omIDType::getInt()", ML_BAD_DATA_TYPE, "Conversion of string ID '" + *this + "' to MLint32 failed. Returning 0.");
76  }
77  return x;
78  }
79 
81  bool isDefault() const {
82  return inherited::empty();
83  }
84 
85 };
86 
89 
91 #define omID_DEFAULT (omIDType())
92 
94 #define omID_MAX (ML_UINT32_MAX / 2 - 1)
95 
96 ML_END_NAMESPACE
97 
98 #endif // __mlObjMgrObjectID_H
omIDTypeT(const char *id)
Constructor from char * argument.
bool isDefault() const
Check for default value.
omIDTypeT()
Standard constructor.
omIDTypeT(const std::basic_string< T > &id)
Constructor from std::string argument.
MLint32 getInt() const
Returns numerical value of object Id if possible.
omIDTypeT(MLint32 id)
Constructor from integer argument.
#define ML_BAD_DATA_TYPE
A wrong or unexpected data type has been passed to an algorithm which often is a programming error; t...
Definition: mlTypeDefs.h:884
signed int MLint32
Definition: mlTypeDefs.h:167
void ML_UTILS_EXPORT printTemplateError(const char *location, MLErrorCode reason, const std::string_view &handling)
omIDTypeT< char > omIDType
Define default type for normal use with the typical string char type.