G4ITType.hh

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 // $Id: G4ITType.hh 64057 2012-10-30 15:04:49Z gcosmo $
00027 //
00028 // Author: Mathieu Karamitros (kara (AT) cenbg . in2p3 . fr) 
00029 //
00030 // WARNING : This class is released as a prototype.
00031 // It might strongly evolve or even disapear in the next releases.
00032 //
00033 // History:
00034 // -----------
00035 // 10 Oct 2011 M.Karamitros created
00036 //
00037 // -------------------------------------------------------------------
00038 
00039 #ifndef G4ITTYPE_HH
00040 #define G4ITTYPE_HH 1
00041 
00042 #include <cstddef>
00043 
00050 struct G4ITType
00051 {
00052 private :
00053     friend G4ITType operator +(const G4ITType& left,const int& right);
00054     friend G4ITType operator -(const G4ITType& left,const int& right);
00055     int fValue;
00056 
00057 public :
00058 
00059     static size_t size();
00060 
00061     G4ITType(const int d_ = 0) : fValue(d_) {;}
00062     G4ITType(const G4ITType & d_) : fValue(d_.fValue){;}
00063     G4ITType & operator=(const G4ITType & rhs);
00064     inline G4ITType & operator=(const int & rhs) { fValue = rhs; return *this;}
00065     inline operator int & () { return fValue; }
00066     inline operator const int & () const { return fValue; }
00067     inline bool operator==(const G4ITType & rhs) const { return fValue == rhs.fValue; }
00068     inline bool operator==(const int & rhs) const { return fValue == rhs; }
00069     inline bool operator<(const G4ITType & rhs) const { return fValue < rhs.fValue; }
00070     inline void operator++() { fValue++; }
00071 };
00072 
00073 inline G4ITType operator +(const G4ITType& left,const int& right) {
00074     G4ITType output( left.fValue + right );
00075     return output;
00076 }
00077 
00078 inline G4ITType operator -(const G4ITType& left,const int& right) {
00079     G4ITType output( left.fValue - right );
00080     return output;
00081 }
00082 
00083 class G4ITTypeManager
00084 {
00085 private:
00086     static G4ITTypeManager* fgInstance ;
00087     G4ITType fLastType;
00088     G4ITTypeManager();
00089     virtual ~G4ITTypeManager();
00090 
00091 public :
00092     G4ITType NewType() ;
00093     size_t size() const;
00094     static G4ITTypeManager* Instance();
00095     static void DeleteInstance();
00096 };
00097 
00098 #define ITDef(T)\
00099 public:\
00100 static G4ITType fType;\
00101 static const G4ITType ITType()\
00102 {\
00103     return fType;\
00104 }\
00105 const G4ITType GetITType() const\
00106 {\
00107     return fType;\
00108 }\
00109 virtual G4bool equal(const G4IT &right) const \
00110 {\
00111     const T& right_mol = (const T&)right ;\
00112     return (this->operator==(right_mol));\
00113 }\
00114 virtual G4bool diff(const G4IT &right) const\
00115 {\
00116     const T& right_mol = (const T&)right ;\
00117     return (this->operator<(right_mol));\
00118 }
00119 
00120 #define ITImp(T) \
00121 G4ITType T::fType = G4ITTypeManager::Instance()->NewType();
00122 
00123 #endif // G4ITTYPE_HH

Generated on Mon May 27 17:48:42 2013 for Geant4 by  doxygen 1.4.7