MongoType
MongoDB Collection Data Dump with BSON Types
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
BSONTypeFormatter.hpp
Go to the documentation of this file.
1 /*
2  * BSONTypeFormatter.hpp
3  *
4  * Created on: Jan 24, 2014
5  * Author: mdeazley
6  */
7 
8 #ifndef BSONTYPEFORMATTER_HPP_
9 #define BSONTYPEFORMATTER_HPP_
10 
11 #include <mongotype.hpp>
12 #include <Parameters.hpp>
13 #include <BSONTypeMap.hpp>
14 
15 namespace mongotype {
16 
17 //----------------------------------------------------------------------------
18 
26 
28 
29 public:
30 
36  BSONTypeFormatter(Parameters& pparams, const BSONElement& e) :
37  BSONTypeMap(e), params(pparams) {
38  }
39 
44  string to_string() {
45  string s;
46  if (params.getTypeMask()) {
47  const BSONTypeElement& bsts = lookup();
48  s = "(";
49  if (params.getTypeMask() & TYPE_NAME) {
50  s += bsts.getName();
51  }
52  if (params.getTypeMask() & TYPE_DESC) {
53  if (s.length()) {
54  s += "/";
55  }
56  s += bsts.getDesc();
57  }
58  if (params.getTypeMask() & TYPE_CODE) {
59  if (s.length()) {
60  s += "/";
61  }
62  s += std::to_string((int)(element.type()));
63  }
64  s += ")";
65  }
66  return s;
67  }
68 
74  return out << bstf.to_string();
75  }
76 };
77 
78 } /* namespace mongotype */
79 
80 #endif /* BSONTYPEFORMATTER_HPP_ */