/// /// Primitive Comparing Method bool Variant::Less(const Variant & rhs) const { if (this->IsNumber() && rhs.IsNumber()) { return ((this->GetFloat()) < (rhs.GetFloat())); } 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(); return str1 < str2; } else if (this->IsFunction() && rhs.IsFunction()) { //Get copies of the strings. std::string str1 = this->GetFunctionName(); std::string str2 = rhs.GetFunctionName(); return (str1 < str2); } //This should be handled more elegantly. return false; }
///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; } }