CARMA C++
SetFilter.h
Go to the documentation of this file.
1 #ifndef CARMA_DBMS_SETFILTER_H
2 #define CARMA_DBMS_SETFILTER_H
3 
15 #include <string>
16 #include <sstream>
17 #include <set>
20 #include "carma/util/StringUtils.h"
21 
22 namespace carma {
23 namespace dbms {
24 
29 template <class T> class SetFilter : public OneComponentFilter {
30 
31 public:
32 
37  SetFilter(const std::set<T>& values, const std::string& columnName)
38  : values_(values) {
39  if(values.size() == 0) {
40  std::string emsg = "Number of elements in values set must be ";
41  emsg += "greater than 0";
43  }
44  columnName_ = columnName;
45  }
46 
50  virtual ~SetFilter() {}
51 
52  std::set<T> getValues() const { return values_; }
53 
61  virtual std::string toString(const std::string& tableName,
62  const std::string& columnName) const {
63  std::ostringstream ss;
64  ss << fullyQualifiedColumnName_(tableName,columnName);
65  ss << " IN (" << carma::util::setToString(values_) << ")";
66  return ss.str();
67  }
68 
73  virtual std::string name() const {
74  return "SetFilter<>";
75  }
76 
77 protected:
78  std::set<T> values_;
79 };
80 
81 }}
82 
83 #endif // CARMA_DBMS_SETFILTER_H
84 
virtual std::string name() const
get the class name for use in log messages etc
Definition: SetFilter.h:73
an exception indicating that an object is in an illegal state for the operation that was called on or...
abstract base class to represent an SQL query one component filter (part of a WHERE clause) ...
SetFilter(const std::set< T > &values, const std::string &columnName)
constuctor
Definition: SetFilter.h:37
virtual std::string toString(const std::string &tableName, const std::string &columnName) const
string representation of the filter.
Definition: SetFilter.h:61
abstract base class to represent a simple one component filter
IllegalArgumentException class.
Common string functions.
virtual ~SetFilter()
destructor, derived classes may want to override
Definition: SetFilter.h:50
#define CARMA_EXCEPTION(x, y)
Trick to get the file name and line number passed to the exception handler.
template to represent a one component set search filter (viz.
Definition: SetFilter.h:29