DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
OrderedAlphabet.ih
1 
31 
32 // IMPLEMENTATION of inline methods.
34 
36 #include <cstdlib>
38 
39 
40 
42 // Implementation of inline methods //
43 
53 inline
54 DGtal::OrderedAlphabet::OrderedAlphabet( char first, unsigned int nb )
55  : myFirst( first ), myNb( nb )
56 {
57  myOrder = new unsigned int[ nb ];
58 
59  ASSERT( ( myOrder != 0 )
60  && "[DGtal::OrderedAlphabet::OrderedAlphabet( char first, int nb )] error in new: no memory left ?" );
61  for ( unsigned int i = 0; i < myNb; ++i )
62  myOrder[ i ] = i;
63 }
64 
71 inline
72 unsigned int
74 {
75  ASSERT( ( c - myFirst ) < (int) myNb
76  && "[DGtal::OrderedAlphabet::order( char c )] invalid letter." );
77  return myOrder[ c - myFirst ];
78 }
79 
88 inline
89 char
90 DGtal::OrderedAlphabet::letter( unsigned int i ) const
91 {
92  ASSERT( i < myNb );
93  for ( unsigned int j = 0; j < myNb; ++j )
94  if ( myOrder[ j ] == i )
95  return myFirst + j;
96  return myFirst;
97 }
98 
99 
105 inline
106 bool
107 DGtal::OrderedAlphabet::less( char c1, char c2 ) const
108 {
109  return myOrder[ c1 - myFirst ] < myOrder[ c2 - myFirst ];
110 }
111 
117 inline
118 bool
119 DGtal::OrderedAlphabet::lessOrEqual( char c1, char c2 ) const
120 {
121  return myOrder[ c1 - myFirst ] <= myOrder[ c2 - myFirst ];
122 }
123 
129 inline
130 bool
131 DGtal::OrderedAlphabet::equal( char c1, char c2 ) const
132 {
133  return c1 == c2;
134 }
135 
136 
138 // Implementation of inline functions and external operators //
139 
146 inline
147 std::ostream&
148 DGtal::operator<< ( std::ostream & out,
149  const OrderedAlphabet & object )
150 {
151  object.selfDisplay ( out );
152  return out;
153 }
154 
155 
156 
157 // //
159 
160