31 #ifndef BSONOBJECTPARSER_HPP_
32 #define BSONOBJECTPARSER_HPP_
131 throw std::logic_error(
string(
"Illegal Stack Item Type Access: ") + (t ==
OBJECT ?
string(
"OBJECT") :
string(
"ELEMENT")) );
145 BSONParserStackItem(
const BSONObj*
object,
const string& pkey,
int pelementIndex,
int pelementCount,
int parrayIndex,
int parrayCount)
159 BSONParserStackItem(
ItemType ptype,
const BSONElement* element,
const string& pkey,
int pelementIndex,
int pelementCount,
int parrayIndex,
int parrayCount)
214 throw std::logic_error(
string(
"toString Undefined ItemType!"));
216 s +=
",\"" +
key +
"\"",
238 typedef std::deque<std::unique_ptr<const BSONParserStackItem>>
Stack;
247 if (
depth() < count) {
248 throw std::logic_error(
string(
"ISE: Insufficient BSONParserStack Stack Entries:(" + to_string(count)) +
"," + to_string(
depth()) +
")" );
273 stack.push_back(unique_ptr<const BSONParserStackItem>(item));
290 return *(
stack[index].get());
292 int i =
depth() + index;
317 void push(
const BSONObj&
object,
const string& key =
string(),
int elementIndex=0,
int elementCount=1,
int arrayIndex=-1,
int arrayCount=0) {
332 void push(
BSONParserStackItem::ItemType type,
const BSONElement& element,
const string& key =
string(),
int elementIndex=0,
int elementCount=1,
int arrayIndex=-1,
int arrayCount=0) {
346 for (
int i=0; i <
depth(); i++) {
472 virtual void parseElementRecursive(
const BSONElement& element,
string& key,
int elementIndex=0,
int elementCount=1,
int arrayIndex = -1,
int arrayCount = 0) {
473 BSONType btype = element.type();
475 case BSONType::Object:
477 const BSONObj& bobj = element.Obj();
478 string k(element.fieldName());
482 case BSONType::Array:
484 stack.
push(BSONParserStackItem::ItemType::ARRAY, element, key, elementIndex, elementCount, arrayIndex, arrayCount);
485 std::vector<BSONElement> elementArray = element.Array();
486 int elementArrayCount = elementArray.size();
488 int elementArrayIndex = 0;
489 for (BSONElement e : elementArray) {
490 string k(e.fieldName());
499 stack.
push(BSONParserStackItem::ItemType::ELEMENT, element, key, elementIndex, elementCount, arrayIndex, arrayCount);
523 virtual void parseObjectRecursive(
const BSONObj&
object,
string& key,
int elementIndex=0,
int elementCount=1,
int arrayIndex = -1,
int arrayCount = 0) {
524 stack.
push(
object, key, elementIndex, elementCount, arrayIndex, arrayCount);
527 object.getFieldNames(keys);
529 int ec = keys.size();
530 for (
string key : keys) {
531 BSONElement e =
object.getField(key);
560 virtual void parse(
const BSONObj&
object) {
562 string emptyString(
"");