CARMA C++
NumericFilter.h
Go to the documentation of this file.
1 #ifndef CARMA_DBMS_NUMERICFILTER_H
2 #define CARMA_DBMS_NUMERICFILTER_H
3 
14 #include <string>
15 #include <sstream>
16 #include <typeinfo>
17 #include <limits>
18 
21 #include "carma/util/compileTimeCheck.h"
22 
23 namespace carma {
24 namespace dbms {
25 
33 template < typename T >
35  public:
46  typedef enum {
47  GREATER_THAN,
48  GREATER_THAN_OR_EQUAL_TO,
49  EQUAL_TO,
50  LESS_THAN,
51  LESS_THAN_OR_EQUAL_TO
52  } SearchType;
53 
59  NumericFilter( T value, SearchType searchType );
60 
64  virtual ~NumericFilter( );
65 
70  T getValue( ) const;
71 
76  SearchType getSearchType( ) const;
77 
85  virtual ::std::string
86  toString( const ::std::string & tableName = "",
87  const ::std::string & columnName = "" ) const;
88 
93  virtual ::std::string name( ) const;
94 
95  protected:
96  T value_;
97  const SearchType searchType_;
98 };
99 
100 
101 } // namespace carma::dbms
102 } // namespace carma
103 
104 
105 template< typename T >
107  const SearchType searchType ) :
108 value_( value ),
109 searchType_(searchType ) {
110  // This line prevents client code instantiating this
111  // templated class using a non-numeric typename T
112 
113  util::compileTimeCheck< ::std::numeric_limits< T >::is_specialized >( );
114 }
115 
116 
117 template< typename T >
119 }
120 
121 
122 template< typename T >
123 T
125  return value_;
126 }
127 
128 
129 template< typename T >
132  return searchType_;
133 }
134 
135 
136 template< typename T >
137 ::std::string
139  const ::std::string & tableName,
140  const ::std::string & columnName ) const
141 {
142  ::std::ostringstream ss;
143 
144  ss << fullyQualifiedColumnName_( tableName, columnName );
145 
146  switch ( searchType_ ) {
147  case GREATER_THAN: ss << " > "; break;
148  case GREATER_THAN_OR_EQUAL_TO: ss << " >= "; break;
149  case EQUAL_TO: ss << " = "; break;
150  case LESS_THAN: ss << " < "; break;
151  case LESS_THAN_OR_EQUAL_TO: ss << " <= "; break;
152 
153  default:
154  {
155  ::std::stringstream emsg;
156  emsg << "Unhandled searchType value " << searchType_;
157  throw CARMA_ERROR(emsg.str());
158  }
159  break;
160  }
161 
162  ss << value_;
163 
164  return ss.str();
165 }
166 
167 
168 template< typename T >
169 ::std::string
171  return "NumericFilter<>";
172 }
173 
174 
175 #endif
SearchType
type of test to perform
Definition: NumericFilter.h:46
abstract base class to represent an SQL query one component filter (part of a WHERE clause) ...
T getValue() const
return the test value
abstract base class to represent a simple one component filter
SearchType getSearchType() const
return the search type
virtual ::std::string toString(const ::std::string &tableName="", const ::std::string &columnName="") const
string representation of the filter.
header that defines a number of common exceptions by including their header files.
virtual ~NumericFilter()
destructor, derived classes may want to override
virtual ::std::string name() const
get the class name for log messages etc.
NumericFilter(T value, SearchType searchType)
constuctor
#define CARMA_ERROR(y)
Trick to get the file name and line number passed to the exception handler.
template to represent a one component numeric search filter.
Definition: NumericFilter.h:34