aboutsummaryrefslogtreecommitdiff
path: root/src/variable.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/variable.cpp67
1 files changed, 67 insertions, 0 deletions
diff --git a/src/variable.cpp b/src/variable.cpp
index 6c9529c..f638dc9 100644
--- a/src/variable.cpp
+++ b/src/variable.cpp
@@ -137,6 +137,13 @@ Variable::Variable( const VarList &lst )
137 uVal.lVal = new VarList( lst ); 137 uVal.lVal = new VarList( lst );
138} 138}
139 139
140Variable::Variable( void *oVal ) :
141 eType( typeOpaque )
142{
143 memset( &uVal, 0, sizeof(uVal) );
144 uVal.oVal = oVal;
145}
146
140Variable::~Variable() 147Variable::~Variable()
141{ 148{
142 if( eType == typeString || eType == typeRef ) 149 if( eType == typeString || eType == typeRef )
@@ -191,6 +198,12 @@ const VarList &Variable::getList() const
191 return *uVal.lVal; 198 return *uVal.lVal;
192} 199}
193 200
201const void *Variable::getOpaque() const
202{
203 if( eType != typeOpaque ) throw Bu::ExceptionBase("Wrong variable type.");
204 return uVal.oVal;
205}
206
194int Variable::toInt() const 207int Variable::toInt() const
195{ 208{
196 switch( eType ) 209 switch( eType )
@@ -302,6 +315,10 @@ Bu::String Variable::toString() const
302 315
303 case typeVersion: 316 case typeVersion:
304 break; 317 break;
318
319 case typeOpaque:
320 sRet = Bu::String("<opaque:%1>").arg( uVal.oVal );
321 break;
305 } 322 }
306 323
307 return sRet; 324 return sRet;
@@ -341,6 +358,9 @@ Variable Variable::toType( Type eNewType ) const
341 358
342 case typeRef: 359 case typeRef:
343 return Variable::mkRef( toString() ); 360 return Variable::mkRef( toString() );
361
362 case typeOpaque:
363 throw Bu::ExceptionBase("Cannot convert opaque types.");
344 } 364 }
345 throw Bu::ExceptionBase("Unhandled case in Variable toType"); 365 throw Bu::ExceptionBase("Unhandled case in Variable toType");
346} 366}
@@ -402,6 +422,9 @@ void Variable::doNegate()
402 422
403 case typeRef: 423 case typeRef:
404 throw Bu::ExceptionBase("You cannot negate reference values."); 424 throw Bu::ExceptionBase("You cannot negate reference values.");
425
426 case typeOpaque:
427 throw Bu::ExceptionBase("You cannot negate opaque values.");
405 } 428 }
406} 429}
407 430
@@ -463,6 +486,14 @@ const Variable &Variable::operator=( const Bu::String &rhs )
463 return *this; 486 return *this;
464} 487}
465 488
489const Variable &Variable::operator=( void *rhs )
490{
491 reset( typeOpaque );
492 uVal.oVal = rhs;
493
494 return *this;
495}
496
466const Variable &Variable::operator+=( const Variable &rhs ) 497const Variable &Variable::operator+=( const Variable &rhs )
467{ 498{
468 switch( eType ) 499 switch( eType )
@@ -575,6 +606,9 @@ bool Variable::operator==( const Variable &rhs ) const
575 606
576 case typeVersion: 607 case typeVersion:
577 return false; 608 return false;
609
610 case typeOpaque:
611 return uVal.oVal == rhs.uVal.oVal;
578 } 612 }
579 613
580 return false; 614 return false;
@@ -613,6 +647,9 @@ bool Variable::operator<( const Variable &rhs ) const
613 647
614 case typeRef: 648 case typeRef:
615 throw Bu::ExceptionBase("You cannot < compare reference values."); 649 throw Bu::ExceptionBase("You cannot < compare reference values.");
650
651 case typeOpaque:
652 throw Bu::ExceptionBase("You cannot < compare opaque values.");
616 } 653 }
617 throw Bu::ExceptionBase("Unhandled case in Variable < compare"); 654 throw Bu::ExceptionBase("Unhandled case in Variable < compare");
618} 655}
@@ -645,6 +682,9 @@ bool Variable::operator>( const Variable &rhs ) const
645 682
646 case typeRef: 683 case typeRef:
647 throw Bu::ExceptionBase("You cannot > compare reference values."); 684 throw Bu::ExceptionBase("You cannot > compare reference values.");
685
686 case typeOpaque:
687 throw Bu::ExceptionBase("You cannot > compare opaque values.");
648 } 688 }
649 throw Bu::ExceptionBase("Unhandled case in Variable > compare"); 689 throw Bu::ExceptionBase("Unhandled case in Variable > compare");
650} 690}
@@ -677,6 +717,9 @@ bool Variable::operator<=( const Variable &rhs ) const
677 717
678 case typeRef: 718 case typeRef:
679 throw Bu::ExceptionBase("You cannot <= compare reference values."); 719 throw Bu::ExceptionBase("You cannot <= compare reference values.");
720
721 case typeOpaque:
722 throw Bu::ExceptionBase("You cannot <= compare opaque values.");
680 } 723 }
681 throw Bu::ExceptionBase("Unhandled case in Variable <= compare"); 724 throw Bu::ExceptionBase("Unhandled case in Variable <= compare");
682} 725}
@@ -709,6 +752,9 @@ bool Variable::operator>=( const Variable &rhs ) const
709 752
710 case typeRef: 753 case typeRef:
711 throw Bu::ExceptionBase("You cannot >= compare reference values."); 754 throw Bu::ExceptionBase("You cannot >= compare reference values.");
755
756 case typeOpaque:
757 throw Bu::ExceptionBase("You cannot >= compare opaque values.");
712 } 758 }
713 throw Bu::ExceptionBase("Unhandled case in Variable >= compare"); 759 throw Bu::ExceptionBase("Unhandled case in Variable >= compare");
714} 760}
@@ -741,6 +787,9 @@ Variable Variable::operator+( const Variable &rhs ) const
741 787
742 case typeRef: 788 case typeRef:
743 throw Bu::ExceptionBase("You cannot add reference values."); 789 throw Bu::ExceptionBase("You cannot add reference values.");
790
791 case typeOpaque:
792 throw Bu::ExceptionBase("You cannot add opaque values.");
744 } 793 }
745 throw Bu::ExceptionBase("Unhandled case in Variable add"); 794 throw Bu::ExceptionBase("Unhandled case in Variable add");
746} 795}
@@ -773,6 +822,9 @@ Variable Variable::operator-( const Variable &rhs ) const
773 822
774 case typeRef: 823 case typeRef:
775 throw Bu::ExceptionBase("You cannot subtract reference values."); 824 throw Bu::ExceptionBase("You cannot subtract reference values.");
825
826 case typeOpaque:
827 throw Bu::ExceptionBase("You cannot subtract opaque values.");
776 } 828 }
777 throw Bu::ExceptionBase("Unhandled case in Variable subtract"); 829 throw Bu::ExceptionBase("Unhandled case in Variable subtract");
778} 830}
@@ -805,6 +857,9 @@ Variable Variable::operator*( const Variable &rhs ) const
805 857
806 case typeRef: 858 case typeRef:
807 throw Bu::ExceptionBase("You cannot multiply reference values."); 859 throw Bu::ExceptionBase("You cannot multiply reference values.");
860
861 case typeOpaque:
862 throw Bu::ExceptionBase("You cannot multiply opaque values.");
808 } 863 }
809 throw Bu::ExceptionBase("Unhandled case in Variable multiply"); 864 throw Bu::ExceptionBase("Unhandled case in Variable multiply");
810} 865}
@@ -837,6 +892,9 @@ Variable Variable::operator/( const Variable &rhs ) const
837 892
838 case typeRef: 893 case typeRef:
839 throw Bu::ExceptionBase("You cannot divide reference values."); 894 throw Bu::ExceptionBase("You cannot divide reference values.");
895
896 case typeOpaque:
897 throw Bu::ExceptionBase("You cannot divide opaque values.");
840 } 898 }
841 throw Bu::ExceptionBase("Unhandled case in Variable divide"); 899 throw Bu::ExceptionBase("Unhandled case in Variable divide");
842} 900}
@@ -868,6 +926,7 @@ Bu::Formatter &operator<<( Bu::Formatter &f, const Variable::Type &t )
868 case Variable::typeList: f << "list"; break; 926 case Variable::typeList: f << "list"; break;
869 case Variable::typeVersion: f << "version"; break; 927 case Variable::typeVersion: f << "version"; break;
870 case Variable::typeRef: f << "ref"; break; 928 case Variable::typeRef: f << "ref"; break;
929 case Variable::typeOpaque: f << "opaque"; break;
871 } 930 }
872 return f; 931 return f;
873} 932}
@@ -885,6 +944,8 @@ Bu::Formatter &operator<<( Bu::Formatter &f, const Variable &v )
885 case Variable::typeList: f << v.getList(); break; 944 case Variable::typeList: f << v.getList(); break;
886 case Variable::typeVersion:/*f << v.getVersion();*/ break; 945 case Variable::typeVersion:/*f << v.getVersion();*/ break;
887 case Variable::typeRef: f << v.getString(); break; 946 case Variable::typeRef: f << v.getString(); break;
947 case Variable::typeOpaque: f << "<opaque:" << v.getOpaque() << ">";
948 break;
888 } 949 }
889 950
890 return f; 951 return f;
@@ -924,6 +985,9 @@ Bu::ArchiveBase &operator<<( Bu::ArchiveBase &ar, const Variable &v )
924 case Variable::typeRef: 985 case Variable::typeRef:
925 ar << *v.uVal.sVal; 986 ar << *v.uVal.sVal;
926 break; 987 break;
988
989 case Variable::typeOpaque:
990 break;
927 } 991 }
928 992
929 return ar; 993 return ar;
@@ -966,6 +1030,9 @@ Bu::ArchiveBase &operator>>( Bu::ArchiveBase &ar, Variable &v )
966 case Variable::typeRef: 1030 case Variable::typeRef:
967 ar >> *v.uVal.sVal; 1031 ar >> *v.uVal.sVal;
968 break; 1032 break;
1033
1034 case Variable::typeOpaque:
1035 break;
969 } 1036 }
970 1037
971 return ar; 1038 return ar;