icedb  version 0.5.1
Snow particle scattering database API
Public Member Functions | Public Attributes | List of all members
icedb::splitSet::intervals< T > Class Template Reference

Class to define and search on intervals. More...

#include <splitSet.hpp>

Collaboration diagram for icedb::splitSet::intervals< T >:
Collaboration graph
[legend]

Public Member Functions

 intervals (const std::string &s="")
 
 intervals (const std::vector< std::string > &s)
 
 ~intervals ()
 
void append (const std::string &instr, const std::map< std::string, std::string > *aliases=nullptr)
 
void append (const std::vector< std::string > &s, const std::map< std::string, std::string > *aliases=nullptr)
 
void append (const intervals< T > &src)
 
bool inRange (const T &val) const
 
bool isNear (const T &val, const T &linSep, const T &factorSep) const
 

Public Attributes

std::vector< std::pair< T, T > > ranges
 

Detailed Description

template<class T>
class icedb::splitSet::intervals< T >

Class to define and search on intervals.

This is a simple class used for searching based on user input. It does not provide interval unions, intersections, etc. It can, however, aid in setting these up, such as for a database query.

Accepts standard paramSet notation, but also adds the '-' range operator, implying that values may be found in a certain range.

Definition at line 67 of file splitSet.hpp.

Constructor & Destructor Documentation

◆ intervals() [1/2]

template<class T >
icedb::splitSet::intervals< T >::intervals ( const std::string &  s = "")

Definition at line 429 of file splitSet.cpp.

429 { if (s.size()) append(s); }
void append(const std::string &instr, const std::map< std::string, std::string > *aliases=nullptr)
Definition: splitSet.cpp:438

◆ intervals() [2/2]

template<class T >
icedb::splitSet::intervals< T >::intervals ( const std::vector< std::string > &  s)

Definition at line 432 of file splitSet.cpp.

432 { append(s); }
void append(const std::string &instr, const std::map< std::string, std::string > *aliases=nullptr)
Definition: splitSet.cpp:438

◆ ~intervals()

template<class T >
icedb::splitSet::intervals< T >::~intervals ( )

Definition at line 435 of file splitSet.cpp.

435 {}

Member Function Documentation

◆ append() [1/3]

template<class T >
void icedb::splitSet::intervals< T >::append ( const std::string &  instr,
const std::map< std::string, std::string > *  aliases = nullptr 
)

Definition at line 438 of file splitSet.cpp.

References icedb::splitSet::extractInterval(), icedb::splitSet::splitSet(), and icedb::splitSet::splitVector().

440  {
441  std::vector<std::string> splits;
442  splitVector(instr, splits, ',');
443  std::set<T> vals;
444  for (const auto &s : splits)
445  {
446  std::map<std::string, std::string> defaliases;
447  if (!aliases) aliases = &defaliases; // Provides a convenient default
448 
449  if (aliases->count(s))
450  {
451  std::string ssubst = aliases->at(s);
452  // Recursively call splitSet to handle bundles of aliases
453  append(ssubst, aliases);
454  }
455  else {
456  T start, end, interval;
457  size_t n;
458  std::string specializer;
459  bool isRange = false;
460  extractInterval(s, start, end, interval, n, specializer);
461  if (specializer == "range")
462  {
463  ranges.push_back(std::pair<T, T>(start, end));
464  } else if (start == end) {
465  ranges.push_back(std::pair<T, T>(start, end));
466  } else {
467  splitSet(start, end, interval, specializer, vals);
468  }
469  }
470  }
471  for (const auto &v : vals)
472  {
473  ranges.push_back(std::pair<T, T>(v, v));
474  }
475  }
void extractInterval(const std::string &instr, T &start, T &end, T &interval, size_t &num, std::string &specializer)
Extracts ICEDB_LOG_INFOrmation from interval notation.
Definition: splitSet.cpp:180
void append(const std::string &instr, const std::map< std::string, std::string > *aliases=nullptr)
Definition: splitSet.cpp:438
void splitVector(const std::string &instr, std::vector< std::string > &out, char delim)
Convenience function to split a null-separated string list into a vector of strings.
Definition: splitSet.cpp:365
void splitSet(const T &Tstart, const T &Tend, const T &Tinterval, const std::string &Tspecializer, std::set< T > &expanded)
Shortcut that already passes parsed ICEDB_LOG_INFOrmation.
Definition: splitSet.cpp:37
std::vector< std::pair< T, T > > ranges
Definition: splitSet.hpp:70
Here is the call graph for this function:

◆ append() [2/3]

template<class T >
void icedb::splitSet::intervals< T >::append ( const std::vector< std::string > &  s,
const std::map< std::string, std::string > *  aliases = nullptr 
)

Definition at line 478 of file splitSet.cpp.

480  {
481  for (const auto &str : s) append(str, aliases);
482  }
void append(const std::string &instr, const std::map< std::string, std::string > *aliases=nullptr)
Definition: splitSet.cpp:438

◆ append() [3/3]

template<class T >
void icedb::splitSet::intervals< T >::append ( const intervals< T > &  src)

Definition at line 485 of file splitSet.cpp.

References icedb::splitSet::intervals< T >::ranges.

486  {
487  ranges.insert(ranges.end(), src.ranges.begin(), src.ranges.end());
488  }
std::vector< std::pair< T, T > > ranges
Definition: splitSet.hpp:70

◆ inRange()

template<class T >
bool icedb::splitSet::intervals< T >::inRange ( const T &  val) const

Definition at line 490 of file splitSet.cpp.

491  {
492  for (const auto &r : ranges)
493  {
494  if (val >= r.first && val < r.second) return true;
495  if (r.first == r.second) {
496  if (val == r.first) return true;
497  }
498  }
499  return false;
500  }
std::vector< std::pair< T, T > > ranges
Definition: splitSet.hpp:70

◆ isNear()

template<class T >
bool icedb::splitSet::intervals< T >::isNear ( const T &  val,
const T &  linSep,
const T &  factorSep 
) const

Definition at line 502 of file splitSet.cpp.

503  {
504  for (const auto &r : ranges)
505  {
506  T lower = (r.first * (static_cast<T>(1) - factorSep)) - linSep,
507  upper = (r.second * (static_cast<T>(1) + factorSep)) + linSep;
508  if (val >= lower && val < upper) return true;
509  }
510  return false;
511  }
std::vector< std::pair< T, T > > ranges
Definition: splitSet.hpp:70

Member Data Documentation

◆ ranges

template<class T>
std::vector<std::pair<T, T> > icedb::splitSet::intervals< T >::ranges

Definition at line 70 of file splitSet.hpp.

Referenced by icedb::splitSet::intervals< T >::append().


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