Geant4 Cross Reference |
1 // Copyright (C) 2010, Guy Barrand. All rights 2 // See the file tools.license for terms. 3 4 #ifndef tools_sg_states 5 #define tools_sg_states 6 7 #include "state" 8 9 //#define TOOLS_SG_STATES_CUR 10 11 namespace tools { 12 namespace sg { 13 14 class states { 15 public: 16 #ifdef TOOLS_SG_STATES_CUR 17 states(unsigned int a_ww,unsigned int a_wh) 18 :m_states(8) 19 ,m_state(&(m_states[0])) 20 ,m_cur_state(0) 21 { 22 m_state->m_ww = a_ww; 23 m_state->m_wh = a_wh; 24 } 25 #else 26 states(unsigned int a_ww,unsigned int a_wh): 27 m_state.m_ww = a_ww; 28 m_state.m_wh = a_wh; 29 } 30 #endif 31 virtual ~states(){} 32 protected: 33 #ifdef TOOLS_SG_STATES_CUR 34 states(const states& a_from) 35 :m_states(a_from.m_states) 36 ,m_state(&(m_states[a_from.m_cur_state])) 37 ,m_cur_state(a_from.m_cur_state) 38 ,m_saved_state(a_from.m_saved_state) 39 {} 40 states& operator=(const states& a_from){ 41 m_states = a_from.m_states; 42 m_state = &(m_states[a_from.m_cur_state]); 43 m_cur_state = a_from.m_cur_state; 44 m_saved_state = a_from.m_saved_state; 45 return *this; 46 } 47 #else 48 states(const states& a_from) 49 :m_states(a_from.m_states) 50 ,m_state(a_from.m_state) 51 ,m_saved_state(a_from.m_saved_state) 52 {} 53 states& operator=(const states& a_from){ 54 m_states = a_from.m_states; 55 m_state = a_from.m_state; 56 m_saved_state = a_from.m_saved_state; 57 return *this; 58 } 59 #endif 60 public: 61 #ifdef TOOLS_SG_STATES_CUR 62 const sg::state& state() const {return *m_st 63 sg::state& state() {return *m_state;} 64 void pop_state() { 65 m_state = &(m_states[m_cur_state]); 66 m_cur_state--; 67 } 68 void push_state() { 69 if((m_cur_state+1)>=(int)m_states.size()) 70 m_states.resize(m_states.size()+5); 71 } 72 m_cur_state++; 73 m_states[m_cur_state] = *m_state; 74 } 75 #else 76 const sg::state& state() const {return m_sta 77 sg::state& state() {return m_state;} 78 void pop_state() { 79 //if(!m_states.size()) return; //throw. 80 m_state = m_states.back(); 81 m_states.pop_back(); 82 } 83 void push_state() {m_states.push_back(m_stat 84 #endif 85 86 void save_state(const sg::state& a_state) {m 87 const sg::state& saved_state() const {return 88 sg::state& saved_state() {return m_saved_sta 89 protected: 90 std::vector<sg::state> m_states; 91 #ifdef TOOLS_SG_STATES_CUR 92 sg::state* m_state; 93 int m_cur_state; 94 #else 95 sg::state m_state; 96 #endif 97 sg::state m_saved_state; 98 }; 99 100 }} 101 102 #endif