Jpp
JLineAttributes.hh
Go to the documentation of this file.
1 #ifndef __JGIZMO__JLINEATTRIBUTES__
2 #define __JGIZMO__JLINEATTRIBUTES__
3 
4 #include <vector>
5 
6 #include "TAttLine.h"
7 
9 
10 
11 /**
12  * \author mdejong
13  */
14 
15 namespace JGIZMO {}
16 namespace JPP { using namespace JGIZMO; }
17 
18 namespace JGIZMO {
19 
21  using JLANG::JPointer;
22 
23 
24  /**
25  * Auxiliary class to set line attributes.
26  */
28  public JRewindableObjectIterator<TAttLine>,
29  public std::vector <TAttLine>
30  {
31  public:
32 
34 
35 
36  /**
37  * Constructor.
38  *
39  * \param width line width
40  */
41  JLineAttributes(const Width_t width = 2) :
42  std::vector<TAttLine>(),
43  index(0)
44  {
45  for (int i = 1; i <= 10; ++i) {
46  push_back(TAttLine(kBlack, i, width));
47  }
48  }
49 
50 
51  /**
52  * Get reference to unique instance of this class object.
53  *
54  * \return reference to this class object
55  */
57  {
58  static JLineAttributes line(2);
59 
60  return line;
61  }
62 
63 
64  /**
65  * Set line width.
66  *
67  * \param width line width
68  */
69  void setLineWidth(const Width_t width)
70  {
71  for (iterator i = this->begin(); i != this->end(); ++i) {
72  i->SetLineWidth(width);
73  }
74  }
75 
76 
77  /**
78  * Rewind index.
79  */
80  virtual void rewind()
81  {
82  index = 0;
83  }
84 
85 
86  /**
87  * Check availability of next element.
88  *
89  * \return true if the iteration has more elements; else false
90  */
91  virtual bool hasNext()
92  {
93  return !this->empty();
94  }
95 
96 
97  /**
98  * Get next element.
99  *
100  * \return pointer to element
101  */
102  virtual const pointer_type& next()
103  {
104  static pointer_type ps;
105 
106  if (index < this->size()) {
107  ps.reset(&this->at(index));
108  }
109 
110  ++index;
111 
112  index = index%this->size();
113 
114  return ps;
115  }
116 
117 
118  /**
119  * Get line attributes.
120  *
121  * \param index index
122  * \return line attributes
123  */
124  const TAttLine& get(unsigned int index)
125  {
126  return this->at(index%this->size());
127  }
128 
129 
130  private:
131  unsigned int index;
132  };
133 }
134 
135 #endif
JGIZMO::JLineAttributes::JLineAttributes
JLineAttributes(const Width_t width=2)
Constructor.
Definition: JLineAttributes.hh:41
JGIZMO::JLineAttributes::hasNext
virtual bool hasNext()
Check availability of next element.
Definition: JLineAttributes.hh:91
JGIZMO::JLineAttributes::getInstance
static JLineAttributes & getInstance()
Get reference to unique instance of this class object.
Definition: JLineAttributes.hh:56
JObjectIterator.hh
std::vector
Definition: JSTDTypes.hh:12
JGIZMO::JLineAttributes
Auxiliary class to set line attributes.
Definition: JLineAttributes.hh:27
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
JLANG::JPointer
Template implementation of class that holds pointer to object(s).
Definition: JPointer.hh:22
JGIZMO::JLineAttributes::get
const TAttLine & get(unsigned int index)
Get line attributes.
Definition: JLineAttributes.hh:124
JGIZMO::JLineAttributes::next
virtual const pointer_type & next()
Get next element.
Definition: JLineAttributes.hh:102
JGIZMO::JLineAttributes::index
unsigned int index
Definition: JLineAttributes.hh:131
JGIZMO::JLineAttributes::setLineWidth
void setLineWidth(const Width_t width)
Set line width.
Definition: JLineAttributes.hh:69
JLANG::JRewindableObjectIterator
Interface for object iteration with rewinding.
Definition: JObjectIterator.hh:362
JGIZMO
Auxiliary applications for use of ROOT and more.
Definition: JCanvas.hh:15
std
Definition: jaanetDictionary.h:36
JGIZMO::JLineAttributes::pointer_type
JRewindableObjectIterator< TAttLine >::pointer_type pointer_type
Definition: JLineAttributes.hh:33
JGIZMO::JLineAttributes::rewind
virtual void rewind()
Rewind index.
Definition: JLineAttributes.hh:80