Mass++ Common Libraries v2.7.5
 All Classes Namespaces Files Functions Variables Enumerations Macros
Classes | Public Types | Public Member Functions | Protected Attributes | List of all members
kome::core::RangeList Class Reference

range list mangement class More...

#include <RangeList.h>

Classes

union  NumberValue
 number value More...
 

Public Types

enum  DefaultType { DEFAULT_NONE, DEFAULT_ALL }
 default type
 

Public Member Functions

 RangeList (const DefaultType type=DEFAULT_NONE)
 constructor
 
virtual ~RangeList ()
 destructor
 
void addIntRange (const int start, const int end)
 adds integer range More...
 
void addDoubleRange (const double start, const double end)
 adds double range More...
 
void clearRanges ()
 clears range
 
unsigned int getNumberOfRanges ()
 gets the number of ranges More...
 
int getStartInt (const unsigned int idx)
 gets range start value More...
 
int getEndInt (const unsigned int idx)
 gets range end value More...
 
double getStartDouble (const unsigned int idx)
 gets range start value More...
 
double getEndDouble (const unsigned int idx)
 gets range end value More...
 
bool checkIntValue (const int val)
 checks integer vlaue More...
 
bool checkDoubleValue (const double val)
 checks double value More...
 
void importIntRanges (const char *str)
 import integer ranges from character string More...
 
void importDoubleRanges (const char *str)
 import double ranges from character string More...
 
std::string exportIntRanges ()
 exports integer ranges to character string More...
 
std::string exportDoubleRanges ()
 exports double ranges to character string More...
 
DefaultType getType ()
 gets default type More...
 

Protected Attributes

DefaultType m_type
 
std::vector< std::pair
< NumberValue, NumberValue > > 
m_ranges
 

Detailed Description

range list mangement class

Definition at line 27 of file RangeList.h.

Member Function Documentation

void kome::core::RangeList::addDoubleRange ( const double  start,
const double  end 
)

adds double range

Parameters
[in]startrange start
[in]endrange end

Definition at line 52 of file RangeList.cpp.

52  {
53  m_ranges.resize( m_ranges.size() + 1 );
54  m_ranges.back().first.dblVal = start;
55  m_ranges.back().second.dblVal = end;
56 }
std::vector< std::pair< NumberValue, NumberValue > > m_ranges
Definition: RangeList.h:66
void kome::core::RangeList::addIntRange ( const int  start,
const int  end 
)

adds integer range

Parameters
[in]startrange start
[in]endrange end

Definition at line 45 of file RangeList.cpp.

45  {
46  m_ranges.resize( m_ranges.size() + 1 );
47  m_ranges.back().first.intVal = start;
48  m_ranges.back().second.intVal = end;
49 }
std::vector< std::pair< NumberValue, NumberValue > > m_ranges
Definition: RangeList.h:66
bool kome::core::RangeList::checkDoubleValue ( const double  val)

checks double value

Parameters
[in]valdouble value
Returns
If true, the specified value is included in ranges list

Definition at line 117 of file RangeList.cpp.

117  {
118  // empty
119  if( m_ranges.size() == 0 ) {
120  return ( m_type == DEFAULT_ALL );
121  }
122 
123  // check
124  for( unsigned int i = 0; i < m_ranges.size(); i++ ) {
125  if( val >= m_ranges[ i ].first.dblVal
126  && val <= m_ranges[ i ].second.dblVal ) { // included
127  return true;
128  }
129  }
130  return false;
131 }
DefaultType m_type
Definition: RangeList.h:53
std::vector< std::pair< NumberValue, NumberValue > > m_ranges
Definition: RangeList.h:66
bool kome::core::RangeList::checkIntValue ( const int  val)

checks integer vlaue

Parameters
[in]valinteger value
Returns
If true, the specified vaue is included in ranges list

Definition at line 100 of file RangeList.cpp.

100  {
101  // empty
102  if( m_ranges.size() == 0 ) {
103  return ( m_type == DEFAULT_ALL );
104  }
105 
106  // check
107  for( unsigned int i = 0; i < m_ranges.size(); i++ ) {
108  if( val >= m_ranges[ i ].first.intVal
109  && val <= m_ranges[ i ].second.intVal ) { // included
110  return true;
111  }
112  }
113  return false;
114 }
DefaultType m_type
Definition: RangeList.h:53
std::vector< std::pair< NumberValue, NumberValue > > m_ranges
Definition: RangeList.h:66
std::string kome::core::RangeList::exportDoubleRanges ( )

exports double ranges to character string

Returns
double ranges character string

Definition at line 262 of file RangeList.cpp.

262  {
263  // string
264  std::string str;
265 
266  // create character string
267  for( unsigned int i = 0; i < m_ranges.size(); i++ ) {
268  // create range string
269  std::string range;
270 
271  double v0 = m_ranges[ i ].first.dblVal;
272  double v1 = m_ranges[ i ].second.dblVal;
273 
274  if( v0 == v1 ) {
275  range = FMT( "%f", v0 );
276  }
277  else {
278  if( v0 != - FLT_MAX ) {
279  range = FMT( "%f", v0 );
280  }
281 
282  range.append( ":" );
283 
284  if( v1 != FLT_MAX ) {
285  range = FMT( "%f", v1 );
286  }
287  }
288 
289  // append
290  if( !str.empty() ) {
291  str.append( "," );
292  }
293  str.append( range );
294  }
295 
296  return str;
297 }
std::vector< std::pair< NumberValue, NumberValue > > m_ranges
Definition: RangeList.h:66
std::string kome::core::RangeList::exportIntRanges ( )

exports integer ranges to character string

Returns
integer ranges character string

Definition at line 224 of file RangeList.cpp.

224  {
225  // string
226  std::string str;
227 
228  // create character string
229  for( unsigned int i = 0; i < m_ranges.size(); i++ ) {
230  // create range string
231  std::string range;
232 
233  int v0 = m_ranges[ i ].first.intVal;
234  int v1 = m_ranges[ i ].second.intVal;
235 
236  if( v0 == v1 ) {
237  range = FMT( "%d", v0 );
238  }
239  else {
240  if( v0 != INT_MIN ) {
241  range = FMT( "%d", v0 );
242  }
243 
244  range.append( ":" );
245 
246  if( v1 != INT_MAX ) {
247  range = FMT( "%d", v1 );
248  }
249  }
250 
251  // append
252  if( !str.empty() ) {
253  str.append( "," );
254  }
255  str.append( range );
256  }
257 
258  return str;
259 }
std::vector< std::pair< NumberValue, NumberValue > > m_ranges
Definition: RangeList.h:66
double kome::core::RangeList::getEndDouble ( const unsigned int  idx)

gets range end value

Parameters
[in]idxrange index
Returns
range end value

Definition at line 92 of file RangeList.cpp.

92  {
93  if( idx >= m_ranges.size() ) {
94  return - FLT_MAX;
95  }
96  return m_ranges[ idx ].second.dblVal;
97 }
std::vector< std::pair< NumberValue, NumberValue > > m_ranges
Definition: RangeList.h:66
int kome::core::RangeList::getEndInt ( const unsigned int  idx)

gets range end value

Parameters
[in]idxrange index
Returns
range end value

Definition at line 77 of file RangeList.cpp.

77  {
78  if( idx >= m_ranges.size() ) {
79  return INT_MIN;
80  }
81  return m_ranges[ idx ].second.intVal;
82 }
std::vector< std::pair< NumberValue, NumberValue > > m_ranges
Definition: RangeList.h:66
unsigned int kome::core::RangeList::getNumberOfRanges ( )

gets the number of ranges

Returns
the number of ranges

Definition at line 64 of file RangeList.cpp.

64  {
65  return m_ranges.size();
66 }
std::vector< std::pair< NumberValue, NumberValue > > m_ranges
Definition: RangeList.h:66
double kome::core::RangeList::getStartDouble ( const unsigned int  idx)

gets range start value

Parameters
[in]idxrange index
Returns
range start value

Definition at line 84 of file RangeList.cpp.

84  {
85  if( idx >= m_ranges.size() ) {
86  return FLT_MAX;
87  }
88  return m_ranges[ idx ].first.dblVal;
89 }
std::vector< std::pair< NumberValue, NumberValue > > m_ranges
Definition: RangeList.h:66
int kome::core::RangeList::getStartInt ( const unsigned int  idx)

gets range start value

Parameters
[in]idxrange index
Returns
range start value

Definition at line 69 of file RangeList.cpp.

69  {
70  if( idx >= m_ranges.size() ) {
71  return INT_MAX;
72  }
73  return m_ranges[ idx ].first.intVal;
74 }
std::vector< std::pair< NumberValue, NumberValue > > m_ranges
Definition: RangeList.h:66
DefaultType kome::core::RangeList::getType ( )

gets default type

Returns
default type

Definition at line 40 of file RangeList.cpp.

40  {
41  return m_type;
42 }
DefaultType m_type
Definition: RangeList.h:53
void kome::core::RangeList::importDoubleRanges ( const char *  str)

import double ranges from character string

Parameters
[in]strdouble ranges character string

Definition at line 179 of file RangeList.cpp.

179  {
180  // clear
181  clearRanges();
182 
183  // token by ","
184  std::vector< std::string > tokens;
185 
186  stringseparate(str, ",", tokens);
187 
188  for( unsigned int i = 0; i < tokens.size(); i++ ) {
189  // token by ":"
190  std::vector< std::string > range;
191 
192  stringseparate(tokens[ i ].c_str(),":",range);
193 
194  if( range.size() == 1 ) { // single value
195  std::string val = trimstring( range[ 0 ].c_str() );
196  double v = double();
197  if( isdouble( val.c_str(), &v ) ) {
198  m_ranges.resize( m_ranges.size() + 1 );
199  m_ranges.back().first.dblVal = v;
200  m_ranges.back().second.dblVal = v;
201  }
202  }
203  else if( range.size() > 1 ) { // range value
204  std::string val0 = trimstring( range[ 0 ].c_str() );
205  std::string val1 = trimstring( range[ 1 ].c_str() );
206 
207  double v0 = double();
208  double v1 = double();
209 
210  bool ret0 = isdouble( val0.c_str(), &v0 );
211  bool ret1 = isdouble( val1.c_str(), &v1 );
212 
213  if( ret0 || ret1 ) {
214  m_ranges.resize( m_ranges.size() + 1 );
215 
216  m_ranges.back().first.dblVal = ( ret0 ? v0 : - FLT_MAX );
217  m_ranges.back().second.dblVal = ( ret1 ? v1 : FLT_MAX );
218  }
219  }
220  }
221 }
void clearRanges()
clears range
Definition: RangeList.cpp:59
bool isdouble(const char *s, double *val)
judge whether sutisfied character string shows real number.
unsigned int stringseparate(const char *s, const char *separator, std::vector< std::string > &tokens)
separates string
std::string trimstring(const char *s)
remove white spaces from both ends of specified string
std::vector< std::pair< NumberValue, NumberValue > > m_ranges
Definition: RangeList.h:66

Here is the call graph for this function:

void kome::core::RangeList::importIntRanges ( const char *  str)

import integer ranges from character string

Parameters
[in]strinteger ranges character string

Definition at line 134 of file RangeList.cpp.

134  {
135  // clear
136  clearRanges();
137 
138  // token by ","
139  std::vector< std::string > tokens;
140 
141  stringseparate(str,",",tokens);
142 
143  for( unsigned int i = 0; i < tokens.size(); i++ ) {
144  // token by ":"
145  std::vector< std::string > range;
146 
147  stringseparate(tokens[ i ].c_str(),":",range);
148 
149  if( range.size() == 1 ) { // single value
150  std::string val = trimstring( range[ 0 ].c_str() );
151  int v = int();
152  if( isint( val.c_str(), 10, &v ) ) {
153  m_ranges.resize( m_ranges.size() + 1 );
154  m_ranges.back().first.intVal = v;
155  m_ranges.back().second.intVal = v;
156  }
157  }
158  else if( range.size() > 1 ) { // range value
159  std::string val0 = trimstring( range[ 0 ].c_str() );
160  std::string val1 = trimstring( range[ 1 ].c_str() );
161 
162  int v0 = int();
163  int v1 = int();
164 
165  bool ret0 = isint( val0.c_str(), 10, &v0 );
166  bool ret1 = isint( val1.c_str(), 10, &v1 );
167 
168  if( ret0 || ret1 ) {
169  m_ranges.resize( m_ranges.size() + 1 );
170 
171  m_ranges.back().first.intVal = ( ret0 ? v0 : INT_MIN );
172  m_ranges.back().second.intVal = ( ret1 ? v1 : INT_MAX );
173  }
174  }
175  }
176 }
void clearRanges()
clears range
Definition: RangeList.cpp:59
unsigned int stringseparate(const char *s, const char *separator, std::vector< std::string > &tokens)
separates string
std::string trimstring(const char *s)
remove white spaces from both ends of specified string
bool isint(const char *s, const int radix, int *val)
judge whether sutisfied character string shows integer number.
std::vector< std::pair< NumberValue, NumberValue > > m_ranges
Definition: RangeList.h:66

Here is the call graph for this function:

Member Data Documentation

std::vector< std::pair< NumberValue, NumberValue > > kome::core::RangeList::m_ranges
protected

ranges

Definition at line 66 of file RangeList.h.

DefaultType kome::core::RangeList::m_type
protected

default type

Definition at line 53 of file RangeList.h.


The documentation for this class was generated from the following files: