DGtal  1.3.beta
Labels.h
1 
17 #pragma once
18 
31 #if defined(Labels_RECURSES)
32 #error Recursive header files inclusion detected in Labels.h
33 #else // defined(Labels_RECURSES)
34 
35 #define Labels_RECURSES
36 
37 #if !defined Labels_h
38 
39 #define Labels_h
40 
42 // Inclusions
43 #include <iostream>
44 #include <vector>
45 #include "DGtal/base/Common.h"
46 #include "DGtal/kernel/CUnsignedNumber.h"
47 #include "DGtal/kernel/CIntegralNumber.h"
49 
50 namespace DGtal
51 {
52 
54  // template class Labels
70  template <unsigned int L, typename TWord = DGtal::uint8_t>
71  class Labels
72  {
73  BOOST_STATIC_ASSERT(( L >= 1 ));
76 
77  public:
78  typedef TWord Word;
80  typedef unsigned int Label;
81  typedef Label SizeType;
82 
83 #define __DGTAL_WORD_NBDIGITS ( sizeof( Word ) * 8 )
84 #define __DGTAL_LABELS_NBWORDS ( (L-1) / __DGTAL_WORD_NBDIGITS + 1 )
85 #define __DGTAL_LABEL_WORD_INDEX( label ) ( label / __DGTAL_WORD_NBDIGITS )
86 #define __DGTAL_LABEL_DIGIT_INDEX( label ) ( label % __DGTAL_WORD_NBDIGITS )
87 
88  protected:
89 
91  Word myLabels[ __DGTAL_LABELS_NBWORDS ];
92 
94  static SizeType _word( Label l );
96  static SizeType _digit( Label l );
98  static Word _mask( Label l );
99 
100  public:
106  public:
108  typedef Label Value;
109  typedef const Value* Pointer;
110  typedef const Value& Reference;
111  typedef std::ptrdiff_t DifferenceType;
112 
113  // ----------------------- std types ----------------------------------
114  typedef Value value_type;
115  typedef std::size_t size_type;
117  typedef Pointer pointer;
119  typedef std::forward_iterator_tag iterator_category;
120 
121  private:
126 
127  public:
132 
136  ConstEnumerator();
137 
143  ConstEnumerator( const Word* address, SizeType firstWord );
144 
149  ConstEnumerator( const ConstEnumerator & other );
150 
156  Self & operator= ( const Self & other );
157 
162  Reference operator*() const;
163 
168  Pointer operator->() const;
169 
174  Self& operator++();
179  Self operator++( int );
180 
186  bool operator==( const Self & other ) const;
187 
193  bool operator!=( const Self & other ) const;
194 
195  };
196 
197  typedef ConstEnumerator ConstIterator;
199 
200  // ----------------------- Standard services ------------------------------
201  public:
202 
206  ~Labels();
207 
211  Labels();
212 
217  Labels ( const Self & other );
218 
224  Self & operator= ( const Self & other );
225 
230  bool test( Label l ) const;
231 
232  // bitset<N>& set ( );
233  // bitset<N>& reset ( );
234 
241  Self& set ( Label l, bool val = true );
242 
248  Self& reset( Label l );
249 
255  Self& flip( Label l );
256 
261  Self& reset();
262 
266  SizeType count() const;
267 
272  static SizeType size();
273 
280  void getLabels( std::vector<Label> & labels ) const;
281 
286  SizeType index( Label l ) const;
287 
291  ConstIterator begin() const;
292 
296  ConstIterator end() const;
297 
298  // ----------------------- Interface --------------------------------------
299  public:
300 
305  void selfDisplay ( std::ostream & out ) const;
306 
311  bool isValid() const;
312 
313  // ------------------------- Protected Datas ------------------------------
314  private:
315  // ------------------------- Private Datas --------------------------------
316  private:
317 
318  // ------------------------- Hidden services ------------------------------
319  protected:
320 
321 
322  // ------------------------- Internals ------------------------------------
323  private:
324 
325  }; // end of class Labels
326 
327 
334  template <unsigned int L, typename TWord>
335  std::ostream&
336  operator<< ( std::ostream & out, const Labels<L, TWord> & object );
337 
338 } // namespace DGtal
339 
340 
342 // Includes inline functions.
343 #include "DGtal/base/Labels.ih"
344 
345 // //
347 
348 #endif // !defined Labels_h
349 
350 #undef Labels_RECURSES
351 #endif // else defined(Labels_RECURSES)
DGtal::Labels::ConstEnumerator::ConstEnumerator
ConstEnumerator()
DGtal::concepts::CUnsignedNumber
Aim: Concept checking for Unsigned numbers. Models of this concept should be listed in NumberTraits c...
Definition: CUnsignedNumber.h:94
DGtal::Labels::index
SizeType index(Label l) const
DGtal::Labels::~Labels
~Labels()
DGtal::Labels::flip
Self & flip(Label l)
DGtal::Labels::ConstEnumerator::pointer
Pointer pointer
Definition: Labels.h:117
DGtal::Labels::Labels
Labels()
DGtal::Labels::ConstEnumerator::Self
ConstEnumerator Self
Definition: Labels.h:107
DGtal::Labels::BOOST_STATIC_ASSERT
BOOST_STATIC_ASSERT((L >=1))
DGtal::Labels::ConstEnumerator::operator->
Pointer operator->() const
DGtal::Labels::Label
unsigned int Label
Definition: Labels.h:80
DGtal::Labels::ConstEnumerator::myWord
Word myWord
current word (modified until 0).
Definition: Labels.h:125
DGtal::Labels::begin
ConstIterator begin() const
DGtal::Labels::isValid
bool isValid() const
DGtal::Labels::SizeType
Label SizeType
Definition: Labels.h:81
DGtal::Labels::_word
static SizeType _word(Label l)
Returns the word in which is the label l.
DGtal::Labels::ConstEnumerator::value_type
Value value_type
Definition: Labels.h:114
DGtal::Labels::ConstEnumerator::reference
Reference reference
Definition: Labels.h:118
DGtal::operator<<
std::ostream & operator<<(std::ostream &out, const ATu0v1< TKSpace, TLinearAlgebra > &object)
DGtal::Labels::set
Self & set(Label l, bool val=true)
DGtal::Labels::count
SizeType count() const
DGtal::Labels::BOOST_CONCEPT_ASSERT
BOOST_CONCEPT_ASSERT((concepts::CUnsignedNumber< TWord >))
DGtal::Labels::ConstEnumerator::size_type
std::size_t size_type
Definition: Labels.h:115
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
DGtal::Labels::getLabels
void getLabels(std::vector< Label > &labels) const
DGtal::Labels::size
static SizeType size()
DGtal::Labels::_mask
static Word _mask(Label l)
Returns the mask for the label l (1 << _digit( l )).
DGtal::Labels::ConstIterator
ConstEnumerator ConstIterator
Definition: Labels.h:197
DGtal::Labels::ConstEnumerator::myWordLabel
Label myWordLabel
index of first label of the current word.
Definition: Labels.h:123
DGtal::Labels::myLabels
Word myLabels[__DGTAL_LABELS_NBWORDS]
Stores the labels as bits. The bit of index l is set if l is in the set.
Definition: Labels.h:91
DGtal::Labels::end
ConstIterator end() const
DGtal::Labels::ConstEnumerator::myWordAddress
const Word * myWordAddress
current address of word
Definition: Labels.h:122
DGtal::Labels::_digit
static SizeType _digit(Label l)
Returns the bit at which is the label l.
DGtal::Labels::ConstEnumerator::Pointer
const typedef Value * Pointer
Definition: Labels.h:109
DGtal::Labels::ConstEnumerator::~ConstEnumerator
~ConstEnumerator()
DGtal::Labels::ConstEnumerator::DifferenceType
std::ptrdiff_t DifferenceType
only positive offsets allowed.
Definition: Labels.h:111
DGtal::Labels::ConstEnumerator::operator!=
bool operator!=(const Self &other) const
DGtal::Labels::Self
Labels< L, Word > Self
Definition: Labels.h:79
DGtal::Labels::operator=
Self & operator=(const Self &other)
DGtal::Labels::ConstEnumerator::operator++
Self & operator++()
DGtal::Labels::ConstEnumerator::Value
Label Value
Definition: Labels.h:108
DGtal::Labels::Word
TWord Word
Definition: Labels.h:78
DGtal::Labels::ConstEnumerator::operator=
Self & operator=(const Self &other)
DGtal::Labels::ConstEnumerator::Reference
const typedef Value & Reference
Definition: Labels.h:110
DGtal::Labels::ConstEnumerator::operator==
bool operator==(const Self &other) const
DGtal::Labels::ConstEnumerator
Definition: Labels.h:105
DGtal::Labels::reset
Self & reset()
DGtal::Labels::const_iterator
ConstIterator const_iterator
Definition: Labels.h:198
DGtal::concepts::CIntegralNumber
Aim: Concept checking for Integral Numbers. Models of this concept should be listed in NumberTraits c...
Definition: CIntegralNumber.h:101
DGtal::Labels::ConstEnumerator::myLabel
Label myLabel
current label
Definition: Labels.h:124
DGtal::Labels::ConstEnumerator::difference_type
DifferenceType difference_type
Definition: Labels.h:116
DGtal::Labels::selfDisplay
void selfDisplay(std::ostream &out) const
DGtal::Labels::ConstEnumerator::operator*
Reference operator*() const
DGtal::Labels
Aim: Stores a set of labels in {O..L-1} as a sequence of bits.
Definition: Labels.h:71
DGtal::Labels::ConstEnumerator::iterator_category
std::forward_iterator_tag iterator_category
Definition: Labels.h:119
DGtal::Labels::test
bool test(Label l) const