AOSharedServiceLibrary
mongo_buffer_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_BUFFER_INTERFACE_H_
26 #define AOSSL_MONGO_INCLUDE_MONGO_BUFFER_INTERFACE_H_
27 
28 #include <bson.h>
29 #include <mongoc.h>
30 #include <exception>
31 #include <string>
32 #include <unordered_map>
33 
34 #include "aossl/core/include/buffers.h"
35 
36 namespace AOSSL {
37 
38 const int MONGO_STRING_UTF8 = 0;
39 
41 struct BsonException: public std::exception {
43  std::string int_msg;
44  const char * what_str;
45 
47  inline BsonException(std::string msg) {
48  int_msg = "Error in Bson Document: " + msg;
49  what_str = int_msg.c_str();
50  }
51 
52  BsonException() {}
53  ~BsonException() throw() {}
54 
56  const char * what() const throw() {
57  return what_str;
58  }
59 };
60 
62 
67  public:
68  virtual ~MongoBufferInterface() {}
70  virtual bool successful() = 0;
72  virtual std::string get_error_message() = 0;
74  virtual bson_t* get_bson() = 0;
76  virtual void add_oid(std::string value) = 0;
78  virtual void get_oid(std::string key, std::string &value) = 0;
80  virtual void add_string(std::string key, std::string value) = 0;
82  virtual void add_string(std::string value, int encoding) = 0;
84  virtual void add_string(std::string value) = 0;
86  virtual void add_string(std::string key, std::string value, int encoding) = 0;
88  virtual void get_string(std::string key, std::string &value) = 0;
90  virtual void add_bool(std::string key, bool value) = 0;
92  virtual void add_bool(bool value) = 0;
94  virtual bool get_bool(std::string key) = 0;
96  virtual void add_int(std::string key, int value) = 0;
98  virtual void add_int(int value) = 0;
100  virtual int get_int(std::string key) = 0;
102  virtual void add_double(std::string key, double value) = 0;
104  virtual void add_double(double value) = 0;
106  virtual double get_double(std::string key) = 0;
108  virtual void add_date(std::string key, int value) = 0;
110  virtual void add_date(int value) = 0;
112  virtual int get_date(std::string key) = 0;
114  virtual void start_array(std::string key) = 0;
116  virtual void end_array() = 0;
118  virtual void start_object(std::string key) = 0;
120  virtual void end_object() = 0;
122  virtual int count_keys() = 0;
124  virtual bool has_field(std::string key) = 0;
126 
129  virtual std::string to_json() = 0;
131 
134  virtual std::string to_json(int string_length) = 0;
135 };
136 
137 } // namespace AOSSL
138 #endif // AOSSL_MONGO_INCLUDE_MONGO_BUFFER_INTERFACE_H_
BSON Exception, used to store document-related errors.
Definition: mongo_buffer_interface.h:41
BsonException(std::string msg)
Create a Mongo Exception, and store the given error message.
Definition: mongo_buffer_interface.h:47
A Structure for holding a BSON Document.
Definition: mongo_buffer_interface.h:66
std::string int_msg
An error message passed on initialization.
Definition: mongo_buffer_interface.h:43
const char * what() const
Show the error message in readable format.
Definition: mongo_buffer_interface.h:56
Definition: mongo_buffer_interface.h:36