MeVisLabToolboxReference
MeVisLab/Standard/Sources/ML/MLObjMgr/ObjMgr/mlObjMgrObjectID.h
Go to the documentation of this file.
00001 // **InsertLicense** code
00002 //-------------------------------------------------------------------------
00005 
00010 //-------------------------------------------------------------------------
00011 
00012 #ifndef __mlObjMgrObjectID_H
00013 #define __mlObjMgrObjectID_H
00014 
00015 #ifndef __MLObjMgrSystem_H
00016 #include "MLObjMgrSystem.h"
00017 #endif
00018 #ifndef __mlTypeDefs_H
00019 #include "mlTypeDefs.h"
00020 #endif
00021 
00022 ML_START_NAMESPACE
00023 
00026    template <typename T>
00027    class omIDTypeT : public std::basic_string<T>
00028    {
00029       typedef std::basic_string<T> inherited;
00030 
00031       public:
00032 
00034          omIDTypeT() : inherited("") {}
00035 
00037          omIDTypeT(MLint32 id)
00038          {
00039            std::basic_ostringstream<T> o;
00040            if (!(o << id)) {
00041               inherited::assign("0");
00042               ML_PRINT_ERROR("omIDType::omIDType(MLint32)", ML_BAD_DATA_TYPE, "Conversion of MLint32 to string failed (result '" + o.str() + "'). Continuing with string id '0'.");
00043            }
00044            else {
00045               inherited::assign(o.str());
00046            }
00047          }
00048 
00050          omIDTypeT(const char *id) : inherited(id) {}
00051 
00053          omIDTypeT(const std::basic_string<T> &id) : inherited(id) {}
00054 
00056          omIDTypeT &operator =(const std::basic_string<T> &id) {
00057             inherited::assign(id);
00058 
00059             return *this;
00060          }
00061 
00063          operator const std::basic_string<T> &() const {
00064             return *this;
00065          }
00066 
00068          MLint32 getInt() const
00069          {
00070            std::basic_istringstream<T> i(*this);
00071            MLint32 x=0;
00072            if (!(i >> x)) {
00073               x = 0;
00074               ML_PRINT_ERROR("omIDType::getInt()", ML_BAD_DATA_TYPE, "Conversion of string ID '" + *this + "' to MLint32 failed. Returning 0.");
00075            }
00076            return x;
00077          }
00078 
00080          const bool isDefault() const {
00081             return inherited::empty();
00082          }
00083 
00084 };
00085 
00087 typedef omIDTypeT<char> omIDType;
00088 
00090 #define omID_DEFAULT (omIDType())
00091 
00093 #define omID_MAX     (ML_UINT32_MAX / 2 - 1)
00094 
00095 ML_END_NAMESPACE
00096 
00097 #endif // __mlObjMgrObjectID_H