AOSharedServiceLibrary
mongo_interface.h
1 /*
2 MIT License Block
3 
4 Copyright (c) 2016 Alex Barry
5 
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to deal
8 in the Software without restriction, including without limitation the rights
9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12 
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15 
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 THE SOFTWARE.
23 */
24 
25 #ifndef AOSSL_MONGO_INCLUDE_MONGO_INTERFACE_H_
26 #define AOSSL_MONGO_INCLUDE_MONGO_INTERFACE_H_
27 
28 #include <string>
29 #include <exception>
30 #include <vector>
31 
33 struct MongoException: public std::exception {
35  std::string int_msg;
36  const char * what_str;
37 
39  inline MongoException(std::string msg) {
40  int_msg = "Error in Mongo Request: " + msg;
41  what_str = int_msg.c_str();
42  }
43 
44  MongoException() {}
45  ~MongoException() throw() {}
46 
48  const char * what() const throw() {
49  return what_str;
50  }
51 };
52 
55  public:
56  virtual ~MongoResponseInterface() {}
58  virtual std::string get_value() = 0;
59  virtual std::string get_err_msg() = 0;
60 };
61 
64  public:
65  virtual ~MongoIteratorInterface() {}
67 
70  virtual MongoResponseInterface* next() = 0;
71 };
72 
74  public:
76  virtual ~MongoInterface() {}
77 
78  // CRUD Operations
79 
81  virtual MongoResponseInterface* create_document(const char * doc, \
82  const char * collection_name) = 0;
84  virtual MongoResponseInterface* create_document(const char * doc) = 0;
86  virtual MongoResponseInterface* create_document(std::string doc) = 0;
88  virtual MongoResponseInterface* create_document(std::string doc, \
89  std::string collection_name) = 0;
90 
92  virtual void delete_document(const char * key) = 0;
94  virtual void delete_document(std::string key) = 0;
96  virtual void delete_document(const char * key, \
97  const char * collection_name) = 0;
99  virtual void delete_document(std::string key, \
100  std::string collection_name) = 0;
101 
103  virtual MongoResponseInterface* load_document(const char * key) = 0;
105  virtual MongoResponseInterface* load_document(std::string key) = 0;
107  virtual MongoResponseInterface* load_document(const char * key, \
108  const char * collection_name) = 0;
110  virtual MongoResponseInterface* load_document(std::string key, \
111  std::string collection_name) = 0;
112 
114  virtual void save_document(const char * doc, const char * key) = 0;
116  virtual void save_document(std::string doc, std::string key) = 0;
118  virtual void save_document(const char * doc, const char * key, \
119  const char * collection_name) = 0;
121  virtual void save_document(std::string doc, std::string key, \
122  std::string collection_name) = 0;
123 
124  // Advanced Operations
125 
127 
130  virtual MongoIteratorInterface* query(const char * query_str, \
131  const char * opts_str) = 0;
133 
136  virtual MongoIteratorInterface* query(std::string query_str, \
137  std::string opts_str) = 0;
139 
142  virtual MongoIteratorInterface* query(const char * query_str, \
143  const char * opts_str, const char * collection_name) = 0;
145 
148  virtual MongoIteratorInterface* query(std::string query_str, \
149  std::string opts_str, std::string collection_name) = 0;
151 
154  virtual MongoIteratorInterface* query(const char * query_str) = 0;
156 
159  virtual MongoIteratorInterface* query(std::string query_str) = 0;
160 };
161 
162 #endif // AOSSL_MONGO_INCLUDE_MONGO_INTERFACE_H_
Interface used to store Mongo Responses.
Definition: mongo_interface.h:54
Returned from Queries in order to iterate over results.
Definition: mongo_interface.h:63
Mongo Exception, used to store errors passed from Mongo.
Definition: mongo_interface.h:33
virtual ~MongoInterface()
Destructor.
Definition: mongo_interface.h:76
const char * what() const
Show the error message in readable format.
Definition: mongo_interface.h:48
std::string int_msg
An error message passed on initialization.
Definition: mongo_interface.h:35
MongoException(std::string msg)
Create a Mongo Exception, and store the given error message.
Definition: mongo_interface.h:39
Definition: mongo_interface.h:73