TableHelper.hpp
Go to the documentation of this file.
1 
18 #pragma once
19 
20 #include <boost/unordered_map.hpp>
21 #include <boost/shared_ptr.hpp>
22 #include <string>
23 #include <map>
24 #include <set>
25 
26 #include "soci/src/core/soci.h"
28 #include "common_type/Object.hpp"
32 #include "common_type/Pattern.hpp"
33 
34 using namespace soci;
35 namespace ISM {
36  typedef std::map<std::string, std::vector<VoteSpecifierPtr> > ObjectTypeToVoteMap;
37  typedef std::map<std::string, PatternPtr> PatternNameToPatternMap;
38  //Access votes for a specific object (given as combination of object type and id).
39  typedef std::map<std::string, std::map<std::string, std::vector<VoteSpecifierPtr> > > ObjectToVoteMap;
40  //Access votes for a specific object (given as combination of object type and id) in a specific scene.
41  typedef std::map<std::string, std::map<std::string, std::map<std::string, std::vector<VoteSpecifierPtr> > > > PatternToObjectToVoteMap;
42 
46  class TableHelper {
47  boost::shared_ptr<session> sqlite;
48  public:
49  /* util */
50  TableHelper(std::string dbfilename = "record.sqlite");
51 
52  ~TableHelper();
53 
54  void createTablesIfNecessary() const;
55  void createColumnsIfNecessary();
56  void createTable(const std::string& tablename, const std::string& sql) const;
57  void dropTable(const std::string& tablename) const;
58  void dropRecordTables() const;
59  void dropTables() const;
60  void dropModelTables() const;
61 
62  bool recordDataExists() const;
63  bool modelDataExists() const;
64 
65  int getLastInsertId(const std::string& tablename) const;
66 
67  const std::set<std::string> getObjectsInPattern(std::string pattern_name);
68 
69 
70  /* Functions that are used by recorder to insert object data into table. */
71  int insertRecordedObject(const boost::shared_ptr<Object>& o, int setId);
72  int insertRecordedObjectSet(const boost::shared_ptr<ObjectSet>& os, const std::string& patternName);
73  int insertRecordedPattern(const std::string& patternName) const;
74  int insertRecordedPattern(const RecordedPatternPtr& pattern) const;
75 
82  int getRecordedPatternId(const std::string& patternName) const;
83  int ensureRecordedPatternName(const std::string& patternName) const;
84 
90  std::vector<std::string> getRecordedPatternNames() const;
91 
92  const RecordedPatternPtr getRecordedPattern(const std::string& patternName) const;
93  const std::vector<int> getSetIds() const;
94  const ObjectSetPtr getRecordedObjectSet(int setId) const;
95 
96  /* model */
97  int insertModelVoteSpecifier(const VoteSpecifierPtr& vote) const;
98  int insertModelPattern(const std::string& patternName) const;
99  int upsertModelPattern(const std::string& patternName, int expectedMaxWeight) const;
100  int insertModelObjectType(const std::string& objectType) const;
101 
108  int getModelPatternId(const std::string& patternName) const;
109  int getModelObjectTypeId(const std::string& objectType) const;
110  int ensureModelPatternName(const std::string& patternName) const;
111  int ensureModelObjectType(const std::string& objectType) const;
112 
118  std::vector<std::string> getModelPatternNames() const;
119 
120  const PatternNameToPatternMap getPatternDefinitionsByName(const std::set<std::string>& patternNames) const;
121 
127  const std::set<std::string> getObjectTypes() const;
128 
134  const std::map<std::string, boost::filesystem::path> getRessourcePaths() const;
135 
136  const std::map<std::string, std::map<std::string, std::string>> getModelWeightsPerTypeAndId() const;
137 
143  const std::set<std::pair<std::string, std::string> > getObjectTypesAndIdsFromModelObjects() const;
144  const std::set<std::pair<std::string, std::string> > getObjectTypesAndIdsFromRecordedObjects() const;
145  const ObjectTypeToVoteMap getVoteSpecifiersForObjectTypes(const std::set<std::string>& objectTypes) const;
146 
153  const std::set<std::pair<std::string, std::string> > getObjectTypesAndIdsBelongingToPattern(const std::string& patternName) const;
154 
162  const ObjectToVoteMap getVoteSpecifiersForPatternAndObjects(const std::string& patternName, std::set<std::pair<std::string, std::string> > objects) const;
163 
169  const std::vector<std::pair<int, ObjectPtr>> getAllMarkerObjects();
170 
178  int updateObjectQuaternion(int dbId, ObjectPtr object);
179 private:
180  int insertRecordedObjectIfNecessary(ObjectPtr object);
181  boost::unordered_map<std::pair<std::string, std::string>, int> objectIdMap_;
182  };
183 
184  typedef boost::shared_ptr<TableHelper> TableHelperPtr;
185 }
boost::unordered_map< std::pair< std::string, std::string >, int > objectIdMap_
std::string patternName
boost::shared_ptr< RecordedPattern > RecordedPatternPtr
boost::shared_ptr< TableHelper > TableHelperPtr
std::map< std::string, std::map< std::string, std::vector< VoteSpecifierPtr > > > ObjectToVoteMap
Definition: TableHelper.hpp:39
boost::shared_ptr< VoteSpecifier > VoteSpecifierPtr
boost::shared_ptr< ObjectSet > ObjectSetPtr
Definition: ObjectSet.hpp:53
std::map< std::string, std::map< std::string, std::map< std::string, std::vector< VoteSpecifierPtr > > > > PatternToObjectToVoteMap
Definition: TableHelper.hpp:41
boost::shared_ptr< session > sqlite
Definition: TableHelper.hpp:47
std::map< std::string, PatternPtr > PatternNameToPatternMap
Definition: TableHelper.hpp:37
this namespace contains all generally usable classes.
std::map< std::string, std::vector< VoteSpecifierPtr > > ObjectTypeToVoteMap
Definition: TableHelper.hpp:36
boost::shared_ptr< Object > ObjectPtr
Definition: Object.hpp:82


asr_lib_ism
Author(s): Hanselmann Fabian, Heller Florian, Heizmann Heinrich, Kübler Marcel, Mehlhaus Jonas, Meißner Pascal, Qattan Mohamad, Reckling Reno, Stroh Daniel
autogenerated on Wed Jan 8 2020 04:02:41