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