Exemplo n.º 1
0
/// Primitive Compare Method
///
bool Variant::Equal(const Variant & rhs) const
{
    //std::cout << "variant equal: "<< *this << "==" << rhs << endl;
    //If they are both integers, make equality be exact.
    //If one is a float, make equality be with some tolerance.

    if(this->IsInteger()  && rhs.IsInteger())
        {
            return (this->GetInteger() == rhs.GetInteger());
        }
    else if (this->IsNumber() && rhs.IsNumber())
        {
            return (fabs(this->GetFloat() - rhs.GetFloat()) < .00000000001);
        }
    else if (this->IsString() && rhs.IsString())
        { //If both are strings, compare them

            //Get copies of the strings.
            std::string str1 = this->GetString();
            std::string str2 = rhs.GetString();

            //strcmp returns 0 if they are identical, a number otherwise
            bool b = (str1 == str2);
            return b;
        }
    else if (this->IsStackSignal() && rhs.IsStackSignal())
        {
            return (this->GetSignal() == rhs.GetSignal());
        }
    return false;
}
Exemplo n.º 2
0
///This overloads the + operator for Variants.
///for strings, this concatenates them.
Variant Variant::operator +(const Variant & rhs) const
{
    pInt i;
    pDouble f;

    if(this->IsInteger()  && rhs.IsInteger())
        {
            i = this->GetInteger() + rhs.GetInteger();
            return Variant(i);
        }
    else if (this->IsNumber() && rhs.IsNumber())
        {
            f = this->GetFloat() + rhs.GetFloat();
            return Variant(f);
        }
    else if (this->IsString() || rhs.IsString())
        {
            std::string  tmp1, tmp2;
            tmp1 = GetString();
            tmp2 = rhs.GetString();
            tmp1 += tmp2;
            return Variant(tmp1);
        }
    else
        //There should be an error emmitted here
        i=0;
    return Variant(i);

}
Exemplo n.º 3
0
///This overloads the * operator for Variants
Variant Variant::operator *(const Variant & rhs) const
{
    pInt i;
    pDouble f;

    if(this->IsInteger()  && rhs.IsInteger())
        {
            i = this->GetInteger() * rhs.GetInteger();
            return Variant(i);
        }
    else if (this->IsNumber() && rhs.IsNumber())
        {

            f = this->GetFloat() * rhs.GetFloat();
            return Variant(f);
        }
    else
        i=0;
    return Variant(i);

}
Exemplo n.º 4
0
///This function makes sure that a value has the proper
///underlying type.  If it doesn't, it will cause a fatal error and 
///report whereabouts the error happened.
void PError::AssertType(Variant v, int type, const string & outsideMessage)
{

	string message;

	switch(type)
		{

		case PEAT_STACK_SIGNAL:
			if( !v.IsStackSignal())
				{
                    message = outsideMessage;
                    message += "Wanted stack signal but got a " + GetTypeName(v) + ": " + v.GetString();
                    SignalFatalError(message);
				}

			break;


		case PEAT_FUNCTION:
			if( !v.IsFunction())
				{
                      message = outsideMessage;
					message += "Wanted function but got a " + GetTypeName(v) + ": "  + v.GetString();
					SignalFatalError(message);
				}

			break;
		case PEAT_FUNCTION_POINTER:
			if( !v.IsFunction())
				{
                    message = outsideMessage;
					message += "Wanted function pointer but got " + GetTypeName(v) + ": " + v.GetString();
					SignalFatalError(message);
				}

			break;
		case PEAT_NUMBER:
			if( !v.IsNumber())
				{
                    message = outsideMessage;
					message += "Wanted number but got " + GetTypeName(v) + ": " + v.GetString();
					SignalFatalError(message);
				}
			break;

		case PEAT_INTEGER:

			if( !v.IsInteger())
				{
                    message = outsideMessage;
                    message += "Wanted integer but got " + GetTypeName(v) + ": " + v.GetString();
					SignalFatalError(message);
				}
			break;
		case PEAT_FLOAT:
			if( !v.IsNumber())
				{
                    message = outsideMessage;
					message +="Wanted floating-point number but got " + GetTypeName(v) + ": "+ v.GetString();
					SignalFatalError(message);
				}
			break;

		case PEAT_STRING:
			if( !v.IsString())
				{
                    message = outsideMessage;
					message +="Wanted string but got " + GetTypeName(v) + ": "+ v.GetString();
					SignalFatalError(message);
				}
			break;

		case PEAT_VARIABLE:
            
			if( v.IsGlobalVariable() || v.IsLocalVariable())
				{
                    return;
                }
            message = outsideMessage;
            message +="Wanted variable but got " + GetTypeName(v) + ": "+ v.GetString();
            SignalFatalError(message);
            
			break;


        case PEAT_AUDIOOUT:
            if(v.IsComplexData())
                {
                    if((v.GetComplexData())->IsAudioOut())
                        {
                            //Everything is fine, return without error.
                            return;
                        }
                }
            message = outsideMessage;
            message +="Wanted AudioOut stream but got " + GetTypeName(v) + ": "+ v.GetString();
            SignalFatalError(message);
			
			break;
        case PEAT_COLOR:
            if(v.IsComplexData())
                {
                    if((v.GetComplexData())->IsColor())
                        {
                            //Everything is fine, return without error.
                            return;
                        }
                }
            
            message = outsideMessage;
            message +="Wanted PEBL Color but got " + GetTypeName(v) + ": "+ v.GetString();
            SignalFatalError(message);           
          break;
          
        case PEAT_ENVIRONMENT:
            
            if(v.IsComplexData())
                {
                    if((v.GetComplexData())->IsEnvironment())
                        {
                            //Everything is fine, return without error.
                            return;
                        }
                }
            message = outsideMessage;
            message +="Wanted Environment but got " + GetTypeName(v) + ": "+ v.GetString();
            SignalFatalError(message);
            
            break;

        case PEAT_FILESTREAM:
            
            if(v.IsComplexData())
                {
                    if((v.GetComplexData())->IsFileStream())
                        {
                            //Everything is fine, return without error.
                            return;
                        }
                }
            message = outsideMessage;
            message +="Wanted FileStream but got " + GetTypeName(v) + ": "+ v.GetString();
            SignalFatalError(message);

          break;
          

        case PEAT_FONT:
            
            if(v.IsComplexData())
                {
                    if((v.GetComplexData())->IsFont())
                        {
                            //Everything is fine, return without error.
                            return;
                        }
                }
            
            message = outsideMessage;
            message +="Wanted font but got " + GetTypeName(v) + ": "+ v.GetString();
            SignalFatalError(message);
            
            break;


        case PEAT_IMAGEBOX:
            
            if(v.IsComplexData())
                {
                    if((v.GetComplexData())->IsImageBox())
                        {
                            //Everything is fine, return without error.
                            return;
                        }
                }
            message = outsideMessage;
            message +="Wanted Image but got " + GetTypeName(v) + ": "+ v.GetString();
            SignalFatalError(message);
            
            break;



        case PEAT_JOYSTICK:
            
            if(v.IsComplexData())
                {
                    if((v.GetComplexData())->IsJoystick())
                        {
                            //Everything is fine, return without error.
                            return;
                        }
                }
            message = outsideMessage;
            message +="Wanted Joystick but got " + GetTypeName(v) + ": "+ v.GetString();
            SignalFatalError(message);
            
            break;


        case PEAT_KEYBOARD:
            
            if(v.IsComplexData())
                {
                    if((v.GetComplexData())->IsKeyboard())
                        {
                            //Everything is fine, return without error.
                            return;
                        }
                }
            message = outsideMessage;
            message +="Wanted Keyboard but got " + GetTypeName(v) + ": "+ v.GetString();
            SignalFatalError(message);
            
            break;

        case PEAT_LIST:
            
            if(v.IsComplexData())
                {
                    if((v.GetComplexData())->IsList())
                        {
                            //Everything is fine, return without error.
                            return;
                        }
                }
            message = outsideMessage;
            message +="Wanted list but got " + GetTypeName(v) + ": "+ v.GetString();
            SignalFatalError(message);

          break;


      case PEAT_WIDGET:
          
          if(v.IsComplexData())
              {
                  if((v.GetComplexData())->IsWidget())
                      {
                          //Everything is fine, return without error.
                          return;
                      }
              }
          message = outsideMessage;
          message +="Wanted Widget but got " + GetTypeName(v) + ": "+ v.GetString();
          SignalFatalError(message);
          
          break;


      case PEAT_OBJECT:
          if(v.IsComplexData())
              {
                  //Any complex data is a PEBLObject (except maybe a list?)
                  return;
              }
          message = outsideMessage;
          message +="Wanted Object but got " + GetTypeName(v) + ": "+ v.GetString();
          SignalFatalError(message);
          
          break;
          

      case PEAT_WINDOW:
          
          if(v.IsComplexData())
              {
                  if((v.GetComplexData())->IsWindow())
                      {
                          //Everything is fine, return without error.
                          return;
                      }
              }
          message = outsideMessage;
          message +="Wanted Window but got " + GetTypeName(v) + ": "+ v.GetString();
          SignalFatalError(message);
          
          break;
          
        case PEAT_TEXTOBJECT:
            
            if(v.IsComplexData())
                {
                    if((v.GetComplexData())->IsTextObject())
                        {
                            //Everything is fine, return without error.
                            return;
                        }
                }
            message = outsideMessage;
            message +="Wanted TextObject but got " + GetTypeName(v) + ": " + v.GetString();
            SignalFatalError(message);

            break;


        case PEAT_LABEL:
            
            if(v.IsComplexData())
                {
                    if((v.GetComplexData())->IsLabel())
                        {
                            //Everything is fine, return without error.
                            return;
                        }
                }
            message = outsideMessage;
            message +="Wanted Label but got " + GetTypeName(v) + ": " + v.GetString();
            SignalFatalError(message);

            break;
            


        case PEAT_TEXTBOX:
            
            if(v.IsComplexData())
                {
                    if((v.GetComplexData())->IsTextBox())
                        {
                            //Everything is fine, return without error.
                            return;
                        }
                }
            message = outsideMessage;
            message +="Wanted Text Box but got " + GetTypeName(v) + ": " + v.GetString();
            SignalFatalError(message);

            break;
            
        case PEAT_NETWORKCONNECTION:
             
            if(v.IsComplexData())
                {
                    if((v.GetComplexData())->IsNetworkConnection())
                        {
                            //Everything is fine, return without error.
                            return;
                        }
                }
            message = outsideMessage;
            message +="Wanted network but got " + GetTypeName(v) + ": "+ v.GetString();
            SignalFatalError(message);

          break;
          
          
        case PEAT_PARALLELPORT:
             
            if(v.IsComplexData())
                {
                    if((v.GetComplexData())->IsParallelPort())
                        {
                            //Everything is fine, return without error.
                            return;
                        }
                }
            message = outsideMessage;
            message +="Wanted parallelport but got " + GetTypeName(v) + ": "+ v.GetString();
            SignalFatalError(message);

          break;
          
        case PEAT_COMPORT:
             
            if(v.IsComplexData())
                {
                    if((v.GetComplexData())->IsComPort())
                        {
                            //Everything is fine, return without error.
                            return;
                        }
                }
            message = outsideMessage;
            message +="Wanted ComPort but got " + GetTypeName(v) + ": "+ v.GetString();
            SignalFatalError(message);

          break;

        case PEAT_MOVIE:
            
            if(v.IsComplexData())
                {
                    if((v.GetComplexData())->IsMovie())
                        {
                            //Everything is fine, return without error.
                            return;
                        }
                }
            message = outsideMessage;
            message +="Wanted Movie but got " + GetTypeName(v) + ": "+ v.GetString();
            SignalFatalError(message);
            
            break;

            
        case PEAT_UNDEFINED:
		default:
            
            message = outsideMessage;
            message += string("Undefined type in PErrorAssert: ") + v.GetString();
            SignalFatalError(message);
            break;
        }

}