Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/Geant4/tools/sg/states is written in an unsupported language. File is not indexed.

0001 // Copyright (C) 2010, Guy Barrand. All rights reserved.
0002 // See the file tools.license for terms.
0003 
0004 #ifndef tools_sg_states
0005 #define tools_sg_states
0006 
0007 #include "state"
0008 
0009 //#define TOOLS_SG_STATES_CUR
0010 
0011 namespace tools {
0012 namespace sg {
0013 
0014 class states {
0015 public:
0016 #ifdef TOOLS_SG_STATES_CUR
0017   states(unsigned int a_ww,unsigned int a_wh)
0018   :m_states(8)
0019   ,m_state(&(m_states[0]))
0020   ,m_cur_state(0)
0021   {
0022     m_state->m_ww = a_ww;
0023     m_state->m_wh = a_wh;
0024   }
0025 #else
0026   states(unsigned int a_ww,unsigned int a_wh):m_states() {
0027     m_state.m_ww = a_ww;
0028     m_state.m_wh = a_wh;
0029   }
0030 #endif
0031   virtual ~states(){}
0032 protected:
0033 #ifdef TOOLS_SG_STATES_CUR
0034   states(const states& a_from)
0035   :m_states(a_from.m_states)
0036   ,m_state(&(m_states[a_from.m_cur_state]))
0037   ,m_cur_state(a_from.m_cur_state)
0038   ,m_saved_state(a_from.m_saved_state)
0039   {}
0040   states& operator=(const states& a_from){
0041     m_states = a_from.m_states;
0042     m_state = &(m_states[a_from.m_cur_state]);
0043     m_cur_state = a_from.m_cur_state;
0044     m_saved_state = a_from.m_saved_state;
0045     return *this;
0046   }
0047 #else
0048   states(const states& a_from)
0049   :m_states(a_from.m_states)
0050   ,m_state(a_from.m_state)
0051   ,m_saved_state(a_from.m_saved_state)
0052   {}
0053   states& operator=(const states& a_from){
0054     m_states = a_from.m_states;
0055     m_state = a_from.m_state;
0056     m_saved_state = a_from.m_saved_state;
0057     return *this;
0058   }
0059 #endif
0060 public:
0061 #ifdef TOOLS_SG_STATES_CUR
0062   const sg::state& state() const {return *m_state;}
0063   sg::state& state() {return *m_state;}
0064   void pop_state() {
0065     m_state = &(m_states[m_cur_state]);
0066     m_cur_state--;
0067   }
0068   void push_state() {
0069     if((m_cur_state+1)>=(int)m_states.size()) {
0070       m_states.resize(m_states.size()+5);
0071     }
0072     m_cur_state++;
0073     m_states[m_cur_state] = *m_state;
0074   }
0075 #else
0076   const sg::state& state() const {return m_state;}
0077   sg::state& state() {return m_state;}
0078   void pop_state() {
0079     //if(!m_states.size()) return; //throw.
0080     m_state = m_states.back();
0081     m_states.pop_back();
0082   }
0083   void push_state() {m_states.push_back(m_state);}
0084 #endif
0085 
0086   void save_state(const sg::state& a_state) {m_saved_state = a_state;}
0087   const sg::state& saved_state() const {return m_saved_state;}
0088   sg::state& saved_state() {return m_saved_state;}
0089 protected:
0090   std::vector<sg::state> m_states;
0091 #ifdef TOOLS_SG_STATES_CUR
0092   sg::state* m_state;
0093   int m_cur_state;
0094 #else
0095   sg::state m_state;
0096 #endif
0097   sg::state m_saved_state;
0098 };
0099 
0100 }}
0101 
0102 #endif