FastBSON
A BSON library that will hopefully be faster and more robust than the one built into mongo-cxx-driver
 All Classes Files Functions Friends
element.hpp
Go to the documentation of this file.
1 
7 #pragma once
8 #include "element.h"
9 #include "typeinfo.h"
10 #include <memory>
11 #include <vector>
12 
13 namespace bson
14 {
15  // Constructors
16  template <typename T>
17  Element::Element(const T& data, const TypeInfo type): m_type(type)
18  {
19  if (!m_type)
20  m_type = default_type<T>();
21  type_check<T>();
22  m_data = std::static_pointer_cast<void>(std::make_shared<T> (data));
23  }
24 
25  template <typename T>
26  const T& Element::data() const
27  {
28  type_check<T>();
29  return *(std::static_pointer_cast<T>(m_data));
30  }
31 
32  template <typename T>
33  void Element::type_check() const
34  {
35  if (!check_convert<T>())
36  throw type_error<T>(m_type);
37  }
38 }
Declaration of a BSON element.
Element()
Default Constructor.
Definition: element.h:38
Enumeration to keep track of types for bson.
const T & data() const
data accessor
Definition: element.hpp:26
Definition: typeinfo.h:40