ROOT_Application  2.0
C++ Core modules and GUIStock
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PolicyChronologic.h
Go to the documentation of this file.
1 
31 #ifndef VEC_CHRONOLOGIC_ORDER
32 #define VEC_CHRONOLOGIC_ORDER
33 
34 #include <vector>
35 #include <algorithm>
36 
38 typedef enum {CHRONO = true, NO_CHRONO = false} EPChrono;
39 
40 // To make clear if public or protected/private function
41 // Maybe can be used directly, without redirection from ListDataStock
42 
48 template <class T>
50 
51 protected:
53  EPChrono bpolicy() const { return EPChrono::CHRONO; }
55  std::string policy() const { return "\t policy VecChronologic"; }
56 
57 
67  void order_impl( std::vector<T> & vec, EPChrono b_chronologic ) {
68 #ifdef DEBUG_CPP
69  std::cout << "Policy <Chronologic> order b_chrono " << b_chronologic << std::endl;
70 #endif
71  // entry is already chronologic nothing to do
72  if ( b_chronologic == EPChrono::CHRONO )
73  return;
74  //else need to invert the data
75 #ifdef DEBUG_CPP
76  std::cout << "Reverse " << std::endl;
77 #endif
78  std::reverse( vec.begin(), vec.end() );
79  return;
80  }
82  const T & chronologic_at_impl( const std::vector<T> & vec_ordered, unsigned int position ) const {
83  //need to check ?? or error ??
84  return vec_ordered [ position ];
85  }
87  const T & no_chronologic_at_impl( const std::vector<T> & vec_ordered, unsigned int position ) const {
88  return vec_ordered [ vec_ordered.size() - position - 1 ];
89  }
92  // used by AddToList to replace the last element
93  void Erase_LastChrono( std::vector<T> & vec_ordered ) { vec_ordered.erase( vec_ordered.end()-1 ) ;}
94 
104  void AddChronoToList( std::vector<T> & vec_ordered, const std::vector<T> & new_vec, const int first_to_skip ) {
105 #ifdef DEBUG_CPP
106  std::cout << "AddChronoToList Chronologic " << std::endl;
107 #endif
108  vec_ordered.insert ( vec_ordered.end(), new_vec.begin()+first_to_skip, new_vec.end() );
109  }
112  time_t FirstChronologic( const std::vector<T> & vec_ordered ) const { return vec_ordered[ 0 ].GetDate(); }
113  time_t LastChronologic( const std::vector<T> & vec_ordered) const { return vec_ordered[ vec_ordered.size()-1 ].GetDate(); }
115 };
116 
122 template <class T>
124 
125 protected:
126 
130  std::string policy() const { return "\t policy VecNoChronologic"; }
131 
141  void order_impl( std::vector<T> & vec, EPChrono b_chronologic ) {
142 #ifdef DEBUG_CPP
143  std::cout << "Policy <NoChronologic> order_impl b_chrono " << b_chronologic << std::endl;
144 #endif
145  // entry is already non-chronologic nothing to do
146  if ( b_chronologic == EPChrono::NO_CHRONO )
147  return;
148  //else need to invert
149 #ifdef DEBUG_CPP
150  std::cout << "Reverse " << std::endl;
151 #endif
152  std::reverse( vec.begin(), vec.end() );
153  return;
154  }
156  //need to check, maybe problem with boundary
157  const T & chronologic_at_impl( const std::vector<T> & vec_no_ordered, unsigned int position ) const {
158  return vec_no_ordered [ vec_no_ordered.size() - position - 1];
159  }
161  const T & no_chronologic_at_impl( const std::vector<T> & vec_no_ordered, unsigned int position ) const {
162  return vec_no_ordered [ position ];
163  }
166  void Erase_LastChrono ( std::vector<T> & vec_no_ordered ) { vec_no_ordered.erase ( vec_no_ordered.begin() );}
167 
177  void AddChronoToList( std::vector<T> & vec_no_ordered, const std::vector<T> & new_vec, const int first_to_skip ) {
178 #ifdef DEBUG_CPP
179  std::cout << "AddChronoToList NoChronologic " << std::endl;
180 #endif
181  // insert a non-chrono list at the beginning of the vector
182  vec_no_ordered.insert ( vec_no_ordered.begin(), new_vec.begin(), new_vec.end()-first_to_skip );
183  }
185 
187  time_t FirstChronologic ( const std::vector<T> & vec_no_ordered ) const { return vec_no_ordered[ vec_no_ordered.size()-1 ].GetDate(); }
188  time_t LastChronologic ( const std::vector<T> & vec_no_ordered ) const { return vec_no_ordered[ 0 ].GetDate(); }
190 };
191 
192 #endif // VEC_CHRONOLOGIC_ORDER
time_t LastChronologic(const std::vector< T > &vec_no_ordered) const
const T & no_chronologic_at_impl(const std::vector< T > &vec_no_ordered, unsigned int position) const
Policy implementation of NoChronologicalAt()
void order_impl(std::vector< T > &vec, EPChrono b_chronologic)
Policy implementation of Order().
const T & chronologic_at_impl(const std::vector< T > &vec_no_ordered, unsigned int position) const
Policy implementation of ChronologicalAt()
time_t FirstChronologic(const std::vector< T > &vec_ordered) const
Return dates of the first and last (chronologically) elements.
void Erase_LastChrono(std::vector< T > &vec_no_ordered)
Erase last chronological data, first in vector in this case.
EPChrono
Define convenient name for the chronology, makes algorithms clearer.
void order_impl(std::vector< T > &vec, EPChrono b_chronologic)
Policy implementation of Order().
time_t FirstChronologic(const std::vector< T > &vec_no_ordered) const
Return dates of the first and last (chronologically) elements.
void Erase_LastChrono(std::vector< T > &vec_ordered)
Delete last chronological data, last in vector in this case.
std::string policy() const
Return the policy as a string, for printing info.
Implements the functions related to the order of the data in the vector.
const T & chronologic_at_impl(const std::vector< T > &vec_ordered, unsigned int position) const
Policy implementation of ChronologicAt()
time_t LastChronologic(const std::vector< T > &vec_ordered) const
const T & no_chronologic_at_impl(const std::vector< T > &vec_ordered, unsigned int position) const
Policy implementation of NoChronologicalAt()
void AddChronoToList(std::vector< T > &vec_ordered, const std::vector< T > &new_vec, const int first_to_skip)
Insert the new_vec vector at the end (chronologically) of vec_ordered.
std::string policy() const
For printing info only.
EPChrono bpolicy() const
Return the current chronology policy, of type EPChrono.
void AddChronoToList(std::vector< T > &vec_no_ordered, const std::vector< T > &new_vec, const int first_to_skip)
Insert the new_vec vector at the beginning of a non-chronological vec_no_ordered. ...
Implements the functions related to the order of the data in the vector.
EPChrono bpolicy() const
Return the current chronology policy, of type EPChrono.