summaryrefslogtreecommitdiff
path: root/src/variable.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/variable.cpp')
-rw-r--r--src/variable.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/variable.cpp b/src/variable.cpp
index ef6760d..adf1511 100644
--- a/src/variable.cpp
+++ b/src/variable.cpp
@@ -1,5 +1,6 @@
1#include "variable.h" 1#include "variable.h"
2 2
3#include <bu/formatter.h>
3#include <stdlib.h> 4#include <stdlib.h>
4 5
5typedef Bu::ExceptionBase VariableException; 6typedef Bu::ExceptionBase VariableException;
@@ -54,6 +55,13 @@ Variable::~Variable()
54 deinitType(); 55 deinitType();
55} 56}
56 57
58Variable Variable::newSituationName( const Bu::String &s )
59{
60 Variable v( tSituation );
61 (*v.sValue) = s;
62 return v;
63}
64
57Variable Variable::to( Type e ) const 65Variable Variable::to( Type e ) const
58{ 66{
59 if( e == eType ) 67 if( e == eType )
@@ -424,3 +432,35 @@ template<> bool Bu::__cmpHashKeys<Variable>( const Variable &a, const Variable &
424 return a == b; 432 return a == b;
425} 433}
426 434
435Bu::Formatter &operator<<( Bu::Formatter &f, const Variable &v )
436{
437 switch( v.eType )
438 {
439 case Variable::tNull:
440 return f << "(null)";
441
442 case Variable::tBool:
443 return f << v.bValue;
444
445 case Variable::tInt:
446 return f << v.iValue;
447
448 case Variable::tFloat:
449 return f << v.fValue;
450
451 case Variable::tString:
452 return f << '"' << *v.sValue << '"';
453
454 case Variable::tSituation:
455 return f << "<<" << *v.sValue << ">>";
456
457 case Variable::tList:
458 return f << *v.lValue;
459
460 case Variable::tDictionary:
461 return f << *v.hValue;
462 }
463
464 return f << "ERROR";
465}
466