Wolframe, 0.0.3

typeSignature.hpp
Go to the documentation of this file.
1 /************************************************************************
2 Copyright (C) 2011 - 2014 Project Wolframe.
3 All rights reserved.
4 
5 This file is part of Project Wolframe.
6 
7 Commercial Usage
8 Licensees holding valid Project Wolframe Commercial licenses may
9 use this file in accordance with the Project Wolframe
10 Commercial License Agreement provided with the Software or,
11 alternatively, in accordance with the terms contained
12 in a written agreement between the licensee and Project Wolframe.
13 
14 GNU General Public License Usage
15 Alternatively, you can redistribute this file and/or modify it
16 under the terms of the GNU General Public License as published by
17 the Free Software Foundation, either version 3 of the License, or
18 (at your option) any later version.
19 
20 Wolframe is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
24 
25 You should have received a copy of the GNU General Public License
26 along with Wolframe. If not, see <http://www.gnu.org/licenses/>.
27 
28 If you have questions regarding the use of this file, please contact
29 Project Wolframe.
30 
31 ************************************************************************/
32 #ifndef _Wolframe_TYPE_SIGNATURE_HPP_INCLUDED
33 #define _Wolframe_TYPE_SIGNATURE_HPP_INCLUDED
34 
37 #include <cstddef>
38 #include <cstring>
39 #include <stdexcept>
40 
41 namespace _Wolframe {
42 namespace utils {
43 
44 #undef _Wolframe_LOWLEVEL_DEBUG
45 #ifdef _Wolframe_LOWLEVEL_DEBUG
46 class TypeSignature
49 {
50  static unsigned int getStmp( unsigned int objid_) {return 2654435761U*(objid_+123);}
51 public:
52  TypeSignature( const char* objname_, unsigned int objid_)
53  :m_objid(objid_)
54  ,m_objinvid(getStmp(objid_))
55  {
56  unsigned int nn = std::strlen( objname_);
57  if (nn >= objnamesize) nn = objnamesize-1;
58  std::memset( m_objname, (char)m_objid, objnamesize);
59  std::memcpy( m_objname, objname_, nn);
60  m_objname[nn] = 0;
61  m_chk = chk();
62  }
63 
64  virtual ~TypeSignature()
65  {
66  verify();
67  }
68 
69  void operator=( const TypeSignature& o)
70  {
71  m_objid = o.m_objid;
72  m_objinvid = o.m_objinvid;
73  }
74 
75 private:
76  void verify() const;
77 
78  unsigned int chk() const
79  {
80  unsigned int xx = 123,ii=0;
81  for (; ii<objnamesize; ++ii) xx += (m_objname[ii]+ii) * 123;
82  return xx;
83  }
84 
85 private:
86  enum {objnamesize=32};
87  unsigned int m_objid;
88  unsigned int m_chk;
89  char m_objname[objnamesize];
90  unsigned int m_objinvid;
91 };
92 
93 #else
94 class TypeSignature
97 {
98 public:
99  TypeSignature( const char*, unsigned int) {}
100  virtual ~TypeSignature(){}
101 };
102 
103 }}//namespace
104 #endif
105 #endif
106 
107 
108 
TypeSignature(const char *, unsigned int)
Definition: typeSignature.hpp:99
virtual ~TypeSignature()
Definition: typeSignature.hpp:100