seqcounter.h
1 /***************************************************************************
2  seqcounter.h - description
3  -------------------
4  begin : Fri Jan 19 2007
5  copyright : (C) 2000-2015 by Thies H. Jochimsen
6  email : thies@jochimsen.de
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef SEQCOUNTER_H
19 #define SEQCOUNTER_H
20 
21 
22 #include <odinseq/seqvec.h>
23 #include <odinseq/seqdriver.h>
24 #include <odinseq/seqtree.h>
25 
32 class SeqCounter; // forward declaration
33 class SeqObjList; // forward declaration
34 
38 class SeqCounterDriver : public SeqDriverBase {
39 
40  public:
41  SeqCounterDriver() {}
42  virtual ~SeqCounterDriver() {}
43 
47  virtual bool prep_driver() = 0;
48 
53  virtual void update_driver(const SeqCounter* counter, const SeqObjList* seqlist, const List<SeqVector,const SeqVector*,const SeqVector&>* vectors) const = 0;
54 
58  virtual double get_preduration () const = 0;
59 
63  virtual double get_postduration() const = 0;
64 
68  virtual double get_preduration_inloop() const = 0;
69 
73  virtual double get_postduration_inloop() const = 0;
74 
75 
80  virtual bool create_program(programContext& context, const STD_string& loopkernel) const = 0;
81 
85  virtual STD_string get_program_head(programContext& context, const STD_string& loopkernel, unsigned int times) const = 0;
86 
90  virtual STD_string get_program_tail(programContext& context, const STD_string& loopkernel, unsigned int times) const = 0;
91 
95  virtual STD_string get_program_head_unrolled(programContext& context, unsigned int index) const = 0;
96 
100  virtual STD_string get_program_iterator(programContext& context) const = 0;
101 
102 
106  virtual void pre_vecprepevent (eventContext& context) const = 0;
107 
112  virtual void post_vecprepevent(eventContext& context, int repcounter) const = 0;
113 
117  virtual void outdate_cache() const = 0;
118 
123  virtual bool unroll_program(const SeqCounter* counter, const SeqObjList* seqlist, const List<SeqVector,const SeqVector*,const SeqVector&>* vectors, programContext& context) const = 0;
124 
128  virtual SeqCounterDriver* clone_driver() const = 0;
129 };
130 
131 
132 
134 
135 
139 class SeqCounter : public Handled<const SeqCounter*>, public virtual SeqTreeObj {
140 
141  public:
145  SeqCounter(const STD_string& object_label = "unnamedSeqCounter");
146 
150  SeqCounter(const SeqCounter& sc);
151 
152 
153  virtual ~SeqCounter() {}
154 
158  SeqCounter& operator = (const SeqCounter& sc);
159 
163  virtual int get_times() const;
164 
165 
169  virtual void add_vector(const SeqVector& seqvector);
170 
171 
172 
173  // counter functions
174  int get_counter() const {return counter;} // also used by SeqVector
175  bool counter_is_active() const {return counter!=-1;}
176  void init_counter(unsigned int start=0) const;
177  void increment_counter() const {counter++;}
178  void disable_counter() const {counter=-1;}
179 
180  // helper functions (also used by platform drivers)
181  bool prep_veciterations() const;
182 
183 
184  protected:
185 
186  // helpers to reduce template code
187  mutable STD_list<const SeqVector*>::const_iterator veciter;
188  STD_list<const SeqVector*>::const_iterator get_vecbegin() const {return vectors.get_const_begin();}
189  STD_list<const SeqVector*>::const_iterator get_vecend() const {return vectors.get_const_end();}
190  unsigned int n_vectors() const {return vectors.size();}
191 
193 
194 
195  void clear_vectorlist() {vectors.clear();}
196 
197 
198  mutable SeqDriverInterface<SeqCounterDriver> counterdriver;
199 
200 
201  // overwriting virtual functions from SeqClass
202  bool prep();
203  void clear_container();
204 
205  private:
206  friend class SeqVector;
207 
208 
209  // helper functions (also used by SeqVector)
210  virtual bool unroll_program(programContext& context) const {return true;}
211 
212  void set_vechandler_for_all() const;
213 
214  mutable int counter;
215 
216 
217 };
218 
222 #endif
virtual bool prep()
Definition: seqclass.h:116
virtual bool unroll_program(const SeqCounter *counter, const SeqObjList *seqlist, const List< SeqVector, const SeqVector *, const SeqVector &> *vectors, programContext &context) const =0
virtual bool create_program(programContext &context, const STD_string &loopkernel) const =0
virtual void outdate_cache() const =0
virtual void pre_vecprepevent(eventContext &context) const =0
Container for sequence objects.
Definition: seqlist.h:86
virtual void clear_container()
Definition: seqclass.h:102
List & clear()
Definition: tjlist_code.h:65
virtual STD_string get_program_tail(programContext &context, const STD_string &loopkernel, unsigned int times) const =0
virtual SeqCounterDriver * clone_driver() const =0
Definition: tjlist.h:105
virtual STD_string get_program_iterator(programContext &context) const =0
virtual bool prep_driver()=0
virtual STD_string get_program_head_unrolled(programContext &context, unsigned int index) const =0
virtual void update_driver(const SeqCounter *counter, const SeqObjList *seqlist, const List< SeqVector, const SeqVector *, const SeqVector &> *vectors) const =0
virtual double get_postduration_inloop() const =0
virtual STD_string get_program_head(programContext &context, const STD_string &loopkernel, unsigned int times) const =0
virtual void post_vecprepevent(eventContext &context, int repcounter) const =0
virtual double get_preduration() const =0
virtual double get_postduration() const =0
virtual double get_preduration_inloop() const =0