Here is how I would implement this function:

    static void addCompoundNode(orion::CompoundValueNode* cvP, const BSONElement& e)
    {
      if ((e.type() != String) && (e.type() != Object) && (e.type() != Array))
        LM_RVE(("unknown BSON type"));

      orion::CompoundValueNode* child = new orion::CompoundValueNode();
      child->name = e.fieldName();

      switch (e.type())
      {
      case String:
        child->type  = orion::CompoundValueNode::Leaf;
        child->value = e.String();
        break;

      case Object:
        compoundObjectResponse(child, e);
        break;

      case Array:
        compoundVectorResponse(child, e);
        break;
      }

      cvP->add(child);
    }