Geant4  9.6.p02
 All Classes 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 64057 2012-10-30 15:04:49Z 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 
50 struct G4ITType
51 {
52 private :
53  friend G4ITType operator +(const G4ITType& left,const int& right);
54  friend G4ITType operator -(const G4ITType& left,const int& right);
55  int fValue;
56 
57 public :
58 
59  static size_t size();
60 
61  G4ITType(const int d_ = 0) : fValue(d_) {;}
62  G4ITType(const G4ITType & d_) : fValue(d_.fValue){;}
63  G4ITType & operator=(const G4ITType & rhs);
64  inline G4ITType & operator=(const int & rhs) { fValue = rhs; return *this;}
65  inline operator int & () { return fValue; }
66  inline operator const int & () const { return fValue; }
67  inline bool operator==(const G4ITType & rhs) const { return fValue == rhs.fValue; }
68  inline bool operator==(const int & rhs) const { return fValue == rhs; }
69  inline bool operator<(const G4ITType & rhs) const { return fValue < rhs.fValue; }
70  inline void operator++() { fValue++; }
71 };
72 
73 inline G4ITType operator +(const G4ITType& left,const int& right) {
74  G4ITType output( left.fValue + right );
75  return output;
76 }
77 
78 inline G4ITType operator -(const G4ITType& left,const int& right) {
79  G4ITType output( left.fValue - right );
80  return output;
81 }
82 
84 {
85 private:
86  static G4ITTypeManager* fgInstance ;
87  G4ITType fLastType;
89  virtual ~G4ITTypeManager();
90 
91 public :
92  G4ITType NewType() ;
93  size_t size() const;
94  static G4ITTypeManager* Instance();
95  static void DeleteInstance();
96 };
97 
98 #define ITDef(T)\
99 public:\
100 static G4ITType fType;\
101 static const G4ITType ITType()\
102 {\
103  return fType;\
104 }\
105 const G4ITType GetITType() const\
106 {\
107  return fType;\
108 }\
109 virtual G4bool equal(const G4IT &right) const \
110 {\
111  const T& right_mol = (const T&)right ;\
112  return (this->operator==(right_mol));\
113 }\
114 virtual G4bool diff(const G4IT &right) const\
115 {\
116  const T& right_mol = (const T&)right ;\
117  return (this->operator<(right_mol));\
118 }
119 
120 #define ITImp(T) \
121 G4ITType T::fType = G4ITTypeManager::Instance()->NewType();
122 
123 #endif // G4ITTYPE_HH