Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4ITType.hh
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 // $Id: G4ITType.hh 74551 2013-10-14 12:59:14Z gcosmo $
27 //
28 // Author: Mathieu Karamitros (kara (AT) cenbg . in2p3 . fr)
29 //
30 // WARNING : This class is released as a prototype.
31 // It might strongly evolve or even disapear in the next releases.
32 //
33 // History:
34 // -----------
35 // 10 Oct 2011 M.Karamitros created
36 //
37 // -------------------------------------------------------------------
38 
39 #ifndef G4ITTYPE_HH
40 #define G4ITTYPE_HH 1
41 
42 #include <cstddef>
43 #include "G4Types.hh"
44 
45 /**
46  * Tag the G4IT
47  * Should be automatically setup by G4IT
48  * using : ITDef(MyIT) and ITImp(MyIT)
49  */
50 
51 struct G4ITType
52 {
53 private :
54  friend G4ITType operator +(const G4ITType& left,const int& right);
55  friend G4ITType operator -(const G4ITType& left,const int& right);
56  int fValue;
57 
58 public :
59 
60  static size_t size();
61 
62  G4ITType(const int d_ = 0) : fValue(d_) {;}
63  G4ITType(const G4ITType & d_) : fValue(d_.fValue){;}
64  G4ITType & operator=(const G4ITType & rhs);
65  inline G4ITType & operator=(const int & rhs) { fValue = rhs; return *this;}
66  inline operator int & () { return fValue; }
67  inline operator const int & () const { return fValue; }
68  inline bool operator==(const G4ITType & rhs) const { return fValue == rhs.fValue; }
69  inline bool operator==(const int & rhs) const { return fValue == rhs; }
70  inline bool operator<(const G4ITType & rhs) const { return fValue < rhs.fValue; }
71  inline void operator++() { fValue++; }
72 };
73 
74 inline G4ITType operator +(const G4ITType& left,const int& right) {
75  G4ITType output( left.fValue + right );
76  return output;
77 }
78 
79 inline G4ITType operator -(const G4ITType& left,const int& right) {
80  G4ITType output( left.fValue - right );
81  return output;
82 }
83 
85 {
86 private:
87  static /*G4ThreadLocal*/ G4ITTypeManager* fgInstance ;
88  static G4ThreadLocal G4ITTypeManager* fgInstance_local ;
89  G4ITType fLastType;
91  virtual ~G4ITTypeManager();
92 
93  size_t fRessource;
94 
95 public :
96  G4ITType NewType() ;
97  size_t size() const;
98  static G4ITTypeManager* Instance();
99  static void DeleteInstance();
100 
101  void ReserveRessource();
102  void ReleaseRessource();
103 };
104 
105 #define ITDef(T)\
106 public:\
107 static G4ITType fType;\
108 static const G4ITType ITType()\
109 {\
110  return fType;\
111 }\
112 const G4ITType GetITType() const\
113 {\
114  return fType;\
115 }\
116 virtual G4bool equal(const G4IT &right) const \
117 {\
118  const T& right_mol = (const T&)right ;\
119  return (this->operator==(right_mol));\
120 }\
121 virtual G4bool diff(const G4IT &right) const\
122 {\
123  const T& right_mol = (const T&)right ;\
124  return (this->operator<(right_mol));\
125 }
126 
127 #define ITImp(T) \
128 G4ITType T::fType = G4ITTypeManager::Instance()->NewType();
129 
130 #endif // G4ITTYPE_HH
G4ITType(const int d_=0)
Definition: G4ITType.hh:62
BasicVector3D< float > operator-(const BasicVector3D< float > &v)
BasicVector3D< float > operator+(const BasicVector3D< float > &v)
G4ITType NewType()
Definition: G4ITType.cc:102
static void DeleteInstance()
Definition: G4ITType.cc:67
#define G4ThreadLocal
Definition: tls.hh:52
friend G4ITType operator-(const G4ITType &left, const int &right)
Definition: G4ITType.hh:79
G4ITType(const G4ITType &d_)
Definition: G4ITType.hh:63
G4ITType & operator=(const G4ITType &rhs)
Definition: G4ITType.cc:51
static G4ITTypeManager * Instance()
Definition: G4ITType.cc:58
G4ITType & operator=(const int &rhs)
Definition: G4ITType.hh:65
static size_t size()
Definition: G4ITType.cc:46
bool operator==(const int &rhs) const
Definition: G4ITType.hh:69
size_t size() const
Definition: G4ITType.cc:97
void ReserveRessource()
Definition: G4ITType.cc:77
void ReleaseRessource()
Definition: G4ITType.cc:83
friend G4ITType operator+(const G4ITType &left, const int &right)
Definition: G4ITType.hh:74
bool operator==(const G4ITType &rhs) const
Definition: G4ITType.hh:68
void operator++()
Definition: G4ITType.hh:71
bool operator<(const G4ITType &rhs) const
Definition: G4ITType.hh:70