Example #1
0
//------------------------------------------------------------------------------
// Real Evaluate()
//------------------------------------------------------------------------------
Real MathElement::Evaluate()
{
   #ifdef DEBUG_EVALUATE
   MessageInterface::ShowMessage
      ("MathElement::Evaluate() this='%s', refObjectName='%s', refObject=<%p>, "
       "elementType=%d\n", GetName().c_str(), refObjectName.c_str(), refObject, elementType);
   #endif
   
   // If this MathElement is function Input, just return since it is handled in
   // the FunctionRunner
   
   if (isFunctionInput)
      throw MathException("MathElement::Evaluate() Function input should "
                          "not be handled here");
   
   if (refObject)
   {
      #ifdef DEBUG_EVALUATE
      MessageInterface::ShowMessage
         ("   refObject=<%p><%p>'%s'\n", refObject, refObject->GetTypeName().c_str(),
          refObject->GetName().c_str());
      #endif
      
      ElementWrapper *wrapper = FindWrapper(refObjectName);
      
      if (elementType == Gmat::REAL_TYPE || elementType == Gmat::RMATRIX_TYPE)
      {
         #ifdef DEBUG_EVALUATE
         MessageInterface::ShowMessage
            ("   wrapper type=%d, desc='%s'\n", wrapper->GetWrapperType(),
             wrapper->GetDescription().c_str());
         #endif
         ///@note ArrayWrapper::EvaluateReal() returns 1x1 matrix as real number
         realValue = wrapper->EvaluateReal();
      }
      else
      {
         throw MathException
            ("MathElement::Evaluate() Cannot Evaluate MathElementType of \"" +
             refObjectName + "\"");
      }
      
      #ifdef DEBUG_EVALUATE
      MessageInterface::ShowMessage
         ("MathElement::Evaluate() It's a parameter: %s realValue = %f\n",
          refObject->GetName().c_str(), realValue);
      #endif
      
      return realValue;
   }
   else
   {
      #ifdef DEBUG_EVALUATE
      MessageInterface::ShowMessage
         ("MathElement::Evaluate() It's a number: realValue = %f\n", realValue);
      #endif
      
      return realValue;
   }
}
Example #2
0
//------------------------------------------------------------------------------
bool MathTree::Validate(std::string &msg)
{
   #ifdef DEBUG_VALIDATE
   MessageInterface::ShowMessage
      ("MathTree::Validate() entered, theWrapperMap=<%p>\n", theWrapperMap);
   #endif
   
   bool retval = true;
   msg = "";
   std::string errmsg = "Cannot use object ";
   
   if (theWrapperMap)
   {
      WrapperMap::iterator iter = theWrapperMap->begin();
      while (iter != theWrapperMap->end())
      {
         ElementWrapper *ew = iter->second;
         #ifdef DEBUG_VALIDATE
         MessageInterface::ShowMessage
            ("   name = '%s', wrapper = <%p>\n", (iter->first).c_str(), ew);
         #endif
         if (ew)
         {
            Gmat::WrapperDataType wrapperType = ew->GetWrapperType();
            #ifdef DEBUG_VALIDATE
            MessageInterface::ShowMessage("   wrapper type = %d\n", wrapperType);
            #endif
            
            // Check for invalid wrapper type
            if (wrapperType == Gmat::STRING_WT || wrapperType == Gmat::STRING_OBJECT_WT ||
                wrapperType == Gmat::OBJECT_WT || wrapperType == Gmat::BOOLEAN_WT ||
                wrapperType == Gmat::ON_OFF_WT || wrapperType == Gmat::UNKNOWN_WRAPPER_TYPE)
            {
               #ifdef DEBUG_VALIDATE
               MessageInterface::ShowMessage
                  ("   '%s' has invalid wrapper type = %d\n", (iter->first).c_str(), wrapperType);
               #endif
               errmsg = errmsg + "\"" + iter->first + "\", ";
               retval = false;
            }
         }
         
         ++iter;
      }
   }
   
   if (!retval)
   {
      // Remove last , from the errmsg
      errmsg = GmatStringUtil::RemoveLastString(errmsg, ", ");
      msg = errmsg + " in a math equation.";
   }
   
   #ifdef DEBUG_VALIDATE
   MessageInterface::ShowMessage
      ("MathTree::Validate() returning %d, msg = '%s'\n", retval, msg.c_str());
   #endif
   
   return retval;
}