Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

StringValue.cpp

Go to the documentation of this file.
00001 // StringValue.cpp: implementation of the CStringValue class.
00002 /*
00003  * Copyright (c) 1996-2000 Erwin Coumans <coockie@acm.org>

00004  *
00005  * Permission to use, copy, modify, distribute and sell this software

00006  * and its documentation for any purpose is hereby granted without fee,

00007  * provided that the above copyright notice appear in all copies and

00008  * that both that copyright notice and this permission notice appear

00009  * in supporting documentation.  Erwin Coumans makes no

00010  * representations about the suitability of this software for any

00011  * purpose.  It is provided "as is" without express or implied warranty.

00012  *
00013  */
00014 
00015 
00016 #include "StringValue.h"
00017 #include "BoolValue.h"
00018 #include "ErrorValue.h"
00019 #include "VoidValue.h"
00020 //#include "FactoryManager.h"
00021 
00022 
00024 // Construction/Destruction
00026 
00027 CStringValue::CStringValue()
00028 /*
00029 pre: false

00030 effect: constructs a new CStringValue

00031 */
00032 {
00033         m_strString = "[Illegal String constructor call]";
00034 }
00035 
00036 CStringValue::CStringValue(CCString txt,CCString name,AllocationTYPE alloctype)
00037 /*
00038 pre:

00039 effect: constructs a new CStringValue containing text txt

00040 */
00041 {
00042         m_strString = txt;
00043         SetName(name);
00044         
00045         if (alloctype==CValue::STACKVALUE)
00046         {
00047                 CValue::DisableRefCount();
00048                 
00049         }
00050         
00051         
00052 }
00053 
00054 
00055 CValue* CStringValue::Calc(VALUE_OPERATOR op, CValue *val)
00056 /*
00057 pre:

00058 ret: a new object containing the result of applying operator op to this

00059 object and val

00060 */
00061 {
00062         //return val->CalrcString(op, this);
00063         return val->CalcFinal(VALUE_STRING_TYPE, op, this);
00064 }
00065 
00066 CValue* CStringValue::CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val)
00067 /*
00068 pre: the type of val is dtype

00069 ret: a new object containing the result of applying operator op to val and

00070 this object

00071 */
00072 {
00073         CValue *ret;
00074         
00075         if (op == VALUE_ADD_OPERATOR) {
00076                 if (dtype == VALUE_ERROR_TYPE)
00077                         ret = new CErrorValue(val->GetText() + op2str(op) +     GetText());
00078                 else
00079                         ret = new CStringValue(val->GetText() + GetText(),"");
00080         } else {
00081                 
00082                 if (dtype == VALUE_STRING_TYPE || dtype == VALUE_EMPTY_TYPE) {
00083                         switch(op) {
00084                         case VALUE_EQL_OPERATOR:
00085                                 ret = new CBoolValue(val->GetText() == GetText());
00086                                 break;
00087                         case VALUE_NEQ_OPERATOR:
00088                                 ret = new CBoolValue(val->GetText() != GetText());
00089                                 break;
00090                         case VALUE_GRE_OPERATOR:
00091                                 ret = new CBoolValue(val->GetText() > GetText());
00092                                 break;
00093                         case VALUE_LES_OPERATOR:
00094                                 ret = new CBoolValue(val->GetText() < GetText());
00095                                 break;
00096                         case VALUE_GEQ_OPERATOR:
00097                                 ret = new CBoolValue(val->GetText() >= GetText());
00098                                 break;
00099                         case VALUE_LEQ_OPERATOR:
00100                                 ret = new CBoolValue(val->GetText() <= GetText());
00101                                 break;
00102                         default:
00103                                 ret =  new CErrorValue(val->GetText() + op2str(op) + "[operator not allowed on strings]");
00104                                 break;
00105                         }
00106                 } else {
00107                         ret =  new CErrorValue(val->GetText() + op2str(op) + "[operator not allowed on strings]");
00108                 }
00109         }
00110         return ret;
00111 }
00112 
00113 
00114 
00115 float CStringValue::GetNumber()

00116 {
00117         return -1;
00118 }
00119 
00120 
00121 
00122 const CCString & CStringValue::GetText()

00123 {
00124         return m_strString;
00125 }
00126 
00127 bool CStringValue::IsEqual(const CCString & other)

00128 {
00129         return (m_strString == other);
00130 }
00131 
00132 CValue* CStringValue::GetReplica()

00133 { 
00134         CStringValue* replica = new CStringValue(*this);
00135         CValue::AddDataToReplica(replica);
00136         return replica;
00137 };
00138 
00139 

Generated at Thu Feb 1 13:03:12 2001 for Ketsji Game Engine by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000