CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Selection.cc
Go to the documentation of this file.
3 //
4 #include <sstream>
5 //
6 #include "CoralBase/AttributeList.h"
7 #include "CoralBase/Attribute.h"
8 
9 const std::vector<std::string>& ora::Selection::selectionTypes(){
10  static const std::vector<std::string> types = { "=","!=",">",">=","<","<=" };
11  return types;
12 }
13 
15 {
16  size_t ind = uniqueString.rfind("_");
17  return uniqueString.substr(0,ind);
18 }
19 
21  static const std::string s_var("ora::ContainerIndex");
22  return s_var;
23 }
24 
25 ora::Selection::Selection():m_items(),m_data( new coral::AttributeList ){
26 }
27 
29 }
30 
32  m_items( rhs.m_items ),
33  m_data( new coral::AttributeList( *rhs.m_data )){
34 }
35 
37  m_items = rhs.m_items;
38  m_data.reset( new coral::AttributeList( *rhs.m_data ) );
39  return *this;
40 }
41 
44  std::stringstream uniqueVarName;
45  unsigned int i = 0;
46  bool notUnique = true;
47  while(notUnique){
48  bool found = false;
49  uniqueVarName.str("");
50  uniqueVarName << varName;
51  uniqueVarName << "_" << i;
52  for(coral::AttributeList::const_iterator iAttr = m_data->begin();
53  iAttr!=m_data->end() && !found; ++iAttr){
54  if( iAttr->specification().name() == uniqueVarName.str() ) found = true;
55  }
56  notUnique = found;
57  i++;
58  }
59  return uniqueVarName.str();
60 }
61 
62 void ora::Selection::addIndexItem( int startIndex,
63  int endIndex ){
64  if(endIndex<startIndex && endIndex>=0) {
65  throwException("Cannot select with endIndex<startIndex.",
66  "Selection::addIndexItem");
67  } else if( startIndex==endIndex && endIndex>=0){
68  std::string varName = uniqueVariableName( indexVariable() );
69  SelectionItemType selType = ora::EQ;
70  m_items.push_back(std::make_pair(varName,selectionTypes()[selType]));
71  m_data->extend<int>(varName);
72  (*m_data)[varName].data<int>() = startIndex;
73  } else {
74  if(startIndex>0){
75  std::string varName0 = uniqueVariableName( indexVariable() );
76  SelectionItemType firstType = ora::GE;
77  m_items.push_back(std::make_pair(varName0,selectionTypes()[firstType]));
78  m_data->extend<int>(varName0);
79  (*m_data)[varName0].data<int>() = startIndex;
80  }
81  if(endIndex>0){
82  std::string varName1 = uniqueVariableName( indexVariable() );
83  SelectionItemType secondType = ora::LE;
84  m_items.push_back(std::make_pair(varName1,selectionTypes()[secondType]));
85  m_data->extend<int>(varName1);
86  (*m_data)[varName1].data<int>() = endIndex;
87  }
88  }
89 }
90 
91 void ora::Selection::addUntypedDataItem( const std::string& dataMemberName,
92  SelectionItemType stype,
93  const std::type_info& primitiveType,
94  void* data ){
95  std::string varName = uniqueVariableName( dataMemberName );
96  m_items.push_back(std::make_pair(varName,selectionTypes()[stype]));
97  m_data->extend( varName, primitiveType );
98  (*m_data)[varName].setValueFromAddress( data );
99 }
100 
101 bool
103  return m_items.empty();
104 }
105 
106 const std::vector<std::pair<std::string,std::string> >&
108  return m_items;
109 }
110 
111 const coral::AttributeList&
113  return *m_data;
114 }
int i
Definition: DBlmapReader.cc:9
std::string uniqueVariableName(const std::string &varName) const
Definition: Selection.cc:43
const coral::AttributeList & data() const
Definition: Selection.cc:112
Selection & operator=(const Selection &rhs)
Definition: Selection.cc:36
static std::string variableNameFromUniqueString(const std::string &uniqueString)
Definition: Selection.cc:14
static std::string indexVariable()
Definition: Selection.cc:20
std::vector< std::pair< std::string, std::string > > m_items
Definition: Selection.h:54
void addIndexItem(int startIndex, int endIndex=endOfRange)
Definition: Selection.cc:62
std::auto_ptr< coral::AttributeList > m_data
Definition: Selection.h:55
void addUntypedDataItem(const std::string &dataMemberName, SelectionItemType stype, const std::type_info &primitiveType, void *data)
Definition: Selection.cc:91
void throwException(const std::string &message, const std::string &methodName) __attribute__((noreturn))
Definition: Exception.cc:10
virtual ~Selection()
Definition: Selection.cc:28
const std::vector< std::pair< std::string, std::string > > & items() const
Definition: Selection.cc:107
bool isEmpty() const
Definition: Selection.cc:102
static const std::vector< std::string > & selectionTypes()
Definition: Selection.cc:9
SelectionItemType
Definition: Selection.h:16