2.50: svn merge https://svn.blender.org/svnroot/bf-blender/trunk/blender -r19323...
[blender.git] / source / gameengine / Expressions / StringValue.cpp
1 // StringValue.cpp: implementation of the CStringValue class.
2 /*
3  * Copyright (c) 1996-2000 Erwin Coumans <coockie@acm.org>
4  *
5  * Permission to use, copy, modify, distribute and sell this software
6  * and its documentation for any purpose is hereby granted without fee,
7  * provided that the above copyright notice appear in all copies and
8  * that both that copyright notice and this permission notice appear
9  * in supporting documentation.  Erwin Coumans makes no
10  * representations about the suitability of this software for any
11  * purpose.  It is provided "as is" without express or implied warranty.
12  *
13  */
14
15 #include "StringValue.h"
16 #include "BoolValue.h"
17 #include "ErrorValue.h"
18 #include "VoidValue.h"
19
20 #ifdef HAVE_CONFIG_H
21 #include <config.h>
22 #endif
23
24 //////////////////////////////////////////////////////////////////////
25 // Construction/Destruction
26 //////////////////////////////////////////////////////////////////////
27
28 CStringValue::CStringValue()
29 /*
30 pre: false
31 effect: constructs a new CStringValue
32 */
33 {
34         m_strString = "[Illegal String constructor call]";
35 }
36
37 CStringValue::CStringValue(STR_String txt,STR_String name,AllocationTYPE alloctype)
38 /*
39 pre:
40 effect: constructs a new CStringValue containing text txt
41 */
42 {
43         m_strString = txt;
44         SetName(name);
45         
46         if (alloctype==CValue::STACKVALUE)
47         {
48                 CValue::DisableRefCount();
49                 
50         }
51         
52         
53 }
54
55
56 CValue* CStringValue::Calc(VALUE_OPERATOR op, CValue *val)
57 /*
58 pre:
59 ret: a new object containing the result of applying operator op to this
60 object and val
61 */
62 {
63         //return val->CalrcString(op, this);
64         return val->CalcFinal(VALUE_STRING_TYPE, op, this);
65 }
66
67 CValue* CStringValue::CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val)
68 /*
69 pre: the type of val is dtype
70 ret: a new object containing the result of applying operator op to val and
71 this object
72 */
73 {
74         CValue *ret;
75         
76         if (op == VALUE_ADD_OPERATOR) {
77                 if (dtype == VALUE_ERROR_TYPE)
78                         ret = new CErrorValue(val->GetText() + op2str(op) +     GetText());
79                 else
80                         ret = new CStringValue(val->GetText() + GetText(),"");
81         } else {
82                 
83                 if (dtype == VALUE_STRING_TYPE || dtype == VALUE_EMPTY_TYPE) {
84                         switch(op) {
85                         case VALUE_EQL_OPERATOR:
86                                 ret = new CBoolValue(val->GetText() == GetText());
87                                 break;
88                         case VALUE_NEQ_OPERATOR:
89                                 ret = new CBoolValue(val->GetText() != GetText());
90                                 break;
91                         case VALUE_GRE_OPERATOR:
92                                 ret = new CBoolValue(val->GetText() > GetText());
93                                 break;
94                         case VALUE_LES_OPERATOR:
95                                 ret = new CBoolValue(val->GetText() < GetText());
96                                 break;
97                         case VALUE_GEQ_OPERATOR:
98                                 ret = new CBoolValue(val->GetText() >= GetText());
99                                 break;
100                         case VALUE_LEQ_OPERATOR:
101                                 ret = new CBoolValue(val->GetText() <= GetText());
102                                 break;
103                         default:
104                                 ret =  new CErrorValue(val->GetText() + op2str(op) + "[operator not allowed on strings]");
105                                 break;
106                         }
107                 } else {
108                         ret =  new CErrorValue(val->GetText() + op2str(op) + "[operator not allowed on strings]");
109                 }
110         }
111         return ret;
112 }
113
114
115
116 double CStringValue::GetNumber()
117 {
118         return -1;
119 }
120
121
122
123 const STR_String & CStringValue::GetText()
124 {
125         return m_strString;
126 }
127
128 bool CStringValue::IsEqual(const STR_String & other)
129 {
130         return (m_strString == other);
131 }
132
133 CValue* CStringValue::GetReplica()
134
135         CStringValue* replica = new CStringValue(*this);
136         CValue::AddDataToReplica(replica);
137         return replica;
138 };
139
140