Example #1
0
//------------------------------------------------------------------------------
bool GmatCommandUtil::FindObject(GmatCommand *cmd, Gmat::ObjectType objType,
                                 const std::string &objName, std::string &cmdName,
                                 GmatCommand **cmdUsing, bool checkWrappers)
{
   if (cmd == NULL)
      return false;
   
   GmatCommand *current = cmd;
   std::string cmdstr = cmd->GetTypeName();
   
   #ifdef DEBUG_COMMAND_FIND_OBJECT
   MessageInterface::ShowMessage
      ("===> GmatCommandUtil::FindObject() entered, objType=%d, objName='%s', "
       "cmd=<%p><%s>\n", objType, objName.c_str(), cmd, cmdstr.c_str());
   #endif
   
   
   while (current != NULL)
   {
      cmdstr = "--- " + current->GetTypeName() + "\n";
      
      #ifdef DEBUG_COMMAND_FIND_OBJECT
      MessageInterface::ShowMessage(cmdstr);
      #endif
      
      try
      {
         StringArray names = current->GetRefObjectNameArray(objType);
         
         for (UnsignedInt i=0; i<names.size(); i++)
         {
            #ifdef DEBUG_COMMAND_FIND_OBJECT
            MessageInterface::ShowMessage("names[%d]=%s\n", i, names[i].c_str());
            #endif
            
            if (names[i] == objName)
            {
               cmdName = current->GetTypeName();
               *cmdUsing = current;
               #ifdef DEBUG_COMMAND_FIND_OBJECT
               MessageInterface::ShowMessage
                  ("CommandUtil::FindObject() returning true, cmdName='%s', "
                   "cmdUsing=<%p>'%s'\n", cmdName.c_str(), *cmdUsing,
                   (*cmdUsing)->GetGeneratingString(Gmat::NO_COMMENTS).c_str());
               #endif
               return true;
            }
         }
      }
      catch (BaseException &e)
      {
         // Use exception to remove Visual C++ warning
         e.GetMessageType();
         #ifdef DEBUG_COMMAND_FIND_OBJECT
         MessageInterface::ShowMessage("*** INTERNAL WARNING *** " + e.GetFullMessage());
         #endif
      }
      
      // go through sub commands
      if ((current->GetChildCommand(0)) != NULL)
      {
         if (FindObjectFromSubCommands(current, 0, objType, objName, cmdName, cmdUsing, checkWrappers))
         {
            #ifdef DEBUG_COMMAND_FIND_OBJECT
            MessageInterface::ShowMessage
               ("CommandUtil::FindObject() returning true, cmdName='%s', "
                "cmdUsing=<%p>'%s'\n", cmdName.c_str(), *cmdUsing,
                (*cmdUsing)->GetGeneratingString(Gmat::NO_COMMENTS).c_str());
            #endif
            
            return true;
         }
      }
      
      // Check for references in the wrappers, if requested
      if (checkWrappers)
      {
         if (current->HasOtherReferenceToObject(objName))
         {
            cmdName = current->GetTypeName();
            *cmdUsing = current;
            #ifdef DEBUG_COMMAND_FIND_OBJECT
            MessageInterface::ShowMessage
               ("CommandUtil::FindObject() returning true (for wrappers), cmdName='%s', "
                "cmdUsing=<%p>'%s'\n", cmdName.c_str(), *cmdUsing,
                (*cmdUsing)->GetGeneratingString(Gmat::NO_COMMENTS).c_str());
            #endif
            return true;
         }
      }

      current = current->GetNext();
   }
   
   #ifdef DEBUG_COMMAND_FIND_OBJECT
   MessageInterface::ShowMessage
      ("===> GmatCommandUtil::FindObject() returning false\n");
   #endif
   return false;
}
Example #2
0
//------------------------------------------------------------------------------
bool GmatCommandUtil::FindObjectFromSubCommands(GmatCommand *brCmd, Integer level,
                         Gmat::ObjectType objType, const std::string &objName,
                         std::string &cmdName, GmatCommand **cmdUsing, bool checkWrappers)
{
   GmatCommand* current = brCmd;
   Integer      childNo = 0;
   GmatCommand* nextInBranch = NULL;
   GmatCommand* child;
   std::string  cmdstr;
   
   while((child = current->GetChildCommand(childNo)) != NULL)
   {
      nextInBranch = child;
      
      while ((nextInBranch != NULL) && (nextInBranch != current))
      {         
         #ifdef DEBUG_COMMAND_FIND_OBJECT
         for (int i=0; i<=level; i++)
            cmdstr = "---" + cmdstr;         
         cmdstr = "--- " + nextInBranch->GetTypeName() + "\n";        
         MessageInterface::ShowMessage("%s", cmdstr.c_str());
         #endif
         
         try
         {
            StringArray names = nextInBranch->GetRefObjectNameArray(objType);
            
            for (UnsignedInt i=0; i<names.size(); i++)
            {
               #ifdef DEBUG_COMMAND_FIND_OBJECT
               MessageInterface::ShowMessage("names[%d]=%s\n", i, names[i].c_str());
               #endif
               
               if (names[i] == objName)
               {
                  cmdName   = nextInBranch->GetTypeName();
                  *cmdUsing = nextInBranch;
                  #ifdef DEBUG_COMMAND_FIND_OBJECT
                  MessageInterface::ShowMessage
                     ("CommandUtil::FindObjectFromSubCommands() returning true, "
                      "cmdName='%s', cmdUsing=<%p>'%s'\n", cmdName.c_str(), *cmdUsing,
                      (*cmdUsing)->GetGeneratingString(Gmat::NO_COMMENTS).c_str());
                  #endif
                  return true;
               }
            }
         }
         catch (BaseException &e)
         {
            // Use exception to remove Visual C++ warning
            e.GetMessageType();
            #ifdef DEBUG_COMMAND_FIND_OBJECT
            MessageInterface::ShowMessage("*** INTERNAL WARNING *** " + e.GetFullMessage());
            #endif
         }
         
         if (nextInBranch->GetChildCommand() != NULL)
            if (FindObjectFromSubCommands(nextInBranch, level+1, objType, objName, cmdName,
                                          cmdUsing, checkWrappers))
            {
               #ifdef DEBUG_COMMAND_FIND_OBJECT
               MessageInterface::ShowMessage
                  ("CommandUtil::FindObjectFromSubCommands() returning true, "
                   "cmdName='%s', cmdUsing=<%p>'%s'\n", cmdName.c_str(), cmdUsing,
                   (*cmdUsing)->GetGeneratingString(Gmat::NO_COMMENTS).c_str());
               #endif
               return true;
            }

         // Check for references in the wrappers, if requested
         if (checkWrappers)
         {
            if (nextInBranch->HasOtherReferenceToObject(objName))
            {
               cmdName   = nextInBranch->GetTypeName();
               *cmdUsing = nextInBranch;
               #ifdef DEBUG_COMMAND_FIND_OBJECT
               MessageInterface::ShowMessage
                  ("CommandUtil::FindObjectFromSubCommands() returning true (for wrappers), cmdName='%s', "
                   "cmdUsing=<%p>'%s'\n", cmdName.c_str(), *cmdUsing,
                   (*cmdUsing)->GetGeneratingString(Gmat::NO_COMMENTS).c_str());
               #endif
               return true;
            }
         }
         nextInBranch = nextInBranch->GetNext();
      }
      
      ++childNo;
   }
   
   #ifdef DEBUG_COMMAND_FIND_OBJECT
   MessageInterface::ShowMessage
      ("===> GmatCommandUtil::FindObjectFromSubCommands() returning false\n");
   #endif
   return false;
}