|
AndroMeta
2.0.0
|
00001 /* 00002 * Copyright 2009-2012 AndroMeta LLC. All rights reserved. 00003 * 00004 * AndroMeta LLC retains all intellectual property and proprietary 00005 * rights to this software and related documentation and any modifications 00006 * thereto. Any use, reproduction, disclosure, or distribution of this 00007 * software and related documentation without an express license agreement 00008 * from AndroMeta LLC is strictly prohibited. 00009 * 00010 */ 00011 00019 #ifndef ANDROMETA_M_VAR_H 00020 #define ANDROMETA_M_VAR_H 00021 00022 #include <ostream> 00023 00024 #include <AndroMeta/MStr.h> 00025 #include <AndroMeta/MVector.h> 00026 #include <AndroMeta/MList.h> 00027 #include <AndroMeta/MMap.h> 00028 #include <AndroMeta/MRational.h> 00029 #include <AndroMeta/MReal.h> 00030 #include <AndroMeta/MNode.h> 00031 00032 namespace Meta{ 00033 00034 class MVar; 00035 class MObjectBase; 00036 class MObject; 00037 00038 typedef MVector<MVar> mvec; 00039 typedef MList<MVar> mlist; 00040 typedef MMap<mstr, MVar> mmap; 00041 00054 extern const class MVar undef; 00055 00056 class MVar{ 00057 public: 00058 typedef uint16_t Type; 00059 00060 static const Type NumericMask = 0x0010; 00061 static const Type DefinedNumericMask = 0x0020; 00062 00063 static const Type Undefined = 0x0010; 00064 static const Type Constant = 0x0031; 00065 static const Type Integer = 0x0032; 00066 static const Type Rational = 0x0033; 00067 static const Type Float = 0x0034; 00068 static const Type Real = 0x0036; 00069 00070 static const Type StringMask = 0x0040; 00071 static const Type String = 0x0040; 00072 static const Type Symbol = 0x0041; 00073 static const Type Function = 0x0042; 00074 00075 static const Type ObjectMask = 0x0080; 00076 static const Type ObjectPointer = 0x0081; 00077 static const Type LocalObject = 0x0082; 00078 static const Type SharedObject = 0x0083; 00079 00080 static const Type RawPointer = 0x0100; 00081 00082 static const Type CodeDataMask = 0x0200; 00083 00084 MVar(); 00085 00086 MVar(bool x); 00087 00088 MVar(uint8_t x); 00089 00090 MVar(int8_t x); 00091 00092 MVar(uint16_t x); 00093 00094 MVar(int16_t x); 00095 00096 MVar(uint32_t x); 00097 00098 MVar(int32_t x); 00099 00100 MVar(uint64_t x); 00101 00102 MVar(int64_t x); 00103 00104 #if defined (__i386__) || defined (__APPLE__) 00105 00106 MVar(long int x); 00107 00108 MVar(unsigned long int x); 00109 00110 #endif 00111 00112 MVar(double x); 00113 00114 MVar(float x); 00115 00116 MVar(const MVar& v); 00117 00118 MVar(const mstr& str, Type t=String); 00119 00120 MVar(const std::string& str, Type t=String); 00121 00122 MVar(const char* str, Type t=String); 00123 00124 MVar(mstr* str, Type t=String); 00125 00126 MVar(MObjectBase* o, Type t=ObjectPointer); 00127 00128 MVar(void* p); 00129 00130 MVar(const MObjectBase& o); 00131 00132 MVar(const mnode& n); 00133 00134 MVar(const mvec& v); 00135 00136 MVar(const mlist& l); 00137 00138 MVar(const mrat& x); 00139 00140 MVar(const mreal& x); 00141 00142 ~MVar(); 00143 00144 bool isTrue() const{ 00145 return type_ == Constant && data_.i == 1; 00146 } 00147 00148 bool isFalse() const{ 00149 return type_ == Constant && data_.i == 0; 00150 } 00151 00152 mstr& asStr(); 00153 00154 const mstr& asStr() const; 00155 00156 mstr& str(){ 00157 return asStr(); 00158 } 00159 00160 const mstr& str() const{ 00161 return asStr(); 00162 } 00163 00164 const char* cstr() const{ 00165 return asStr().c_str(); 00166 } 00167 00168 void convertNode(const mnode& n, bool indexKeys=false); 00169 00180 mstr toStr(bool concise=true, 00181 bool quote=false, 00182 bool mml=true) const; 00183 00184 const char* asCStr() const{ 00185 return asStr().c_str(); 00186 } 00187 00188 std::string toStdStr() const{ 00189 return toStr().str(); 00190 } 00191 00192 const int64_t& asLong() const; 00193 00194 int64_t& asLong(); 00195 00196 int64_t toLong() const; 00197 00198 double& asDouble(); 00199 00200 const double& asDouble() const; 00201 00202 double toDouble() const; 00203 00204 const mrat& asRat() const; 00205 00206 mrat& asRat(); 00207 00208 mrat toRat() const; 00209 00210 const mreal& asReal() const; 00211 00212 mreal& asReal(); 00213 00214 mreal toReal() const; 00215 00216 size_t asSize() const; 00217 00218 MObjectBase* asObj() const; 00219 00220 MObjectBase* obj() const; 00221 00222 #ifndef ANDROMETA_NO_OBJECT 00223 00224 MObject* oc() const; 00225 00226 #endif 00227 00228 void* asPtr() const; 00229 00230 void* ptr() const{ 00231 return asPtr(); 00232 } 00233 00234 const mvec& vec() const; 00235 00236 mvec& vec(); 00237 00238 operator const mvec&() const{ 00239 return vec(); 00240 } 00241 00242 operator mvec&(){ 00243 return vec(); 00244 } 00245 00246 const mlist& list() const; 00247 00248 mlist& list(); 00249 00250 operator const mlist&() const{ 00251 return list(); 00252 } 00253 00254 operator mlist&(){ 00255 return list(); 00256 } 00257 00258 const mmap& map() const; 00259 00260 mmap& map(); 00261 00265 mvec toVec() const; 00266 00270 mlist toList() const; 00271 00272 operator const mmap&() const{ 00273 return map(); 00274 } 00275 00276 operator mmap&(){ 00277 return map(); 00278 } 00279 00280 operator double() const{ 00281 return toDouble(); 00282 } 00283 00284 operator uint8_t() const{ 00285 return toLong(); 00286 } 00287 00288 operator int8_t() const{ 00289 return toLong(); 00290 } 00291 00292 operator uint16_t() const{ 00293 return toLong(); 00294 } 00295 00296 operator int16_t() const{ 00297 return toLong(); 00298 } 00299 00300 operator uint32_t() const{ 00301 return (uint32_t)toLong(); 00302 } 00303 00304 operator int32_t() const{ 00305 return (int32_t)toLong(); 00306 } 00307 00308 operator uint64_t() const{ 00309 return toLong(); 00310 } 00311 00312 operator int64_t() const{ 00313 return toLong(); 00314 } 00315 00316 #if defined (__i386__) || defined (__APPLE__) 00317 00318 operator unsigned long int() const{ 00319 return (unsigned long int)toLong(); 00320 } 00321 00322 operator long int() const{ 00323 return (long int)toLong(); 00324 } 00325 00326 #endif 00327 00328 operator const char*() const{ 00329 return asStr().c_str(); 00330 } 00331 00332 operator mstr&(){ 00333 return str(); 00334 } 00335 00336 operator const mstr&() const{ 00337 return asStr(); 00338 } 00339 00340 operator float() const{ 00341 return toDouble(); 00342 } 00343 00344 operator bool() const{ 00345 return toBool(); 00346 } 00347 00348 MVar& operator=(const MVar& v); 00349 00350 MVar& operator=(const MStr& s); 00351 00352 MVar& operator=(const std::string& s){ 00353 return *this = MStr(s); 00354 } 00355 00356 MVar& operator=(const char* s){ 00357 return *this = MStr(s); 00358 } 00359 00360 template<typename T> 00361 MVar& operator=(const T& t){ 00362 return *this = MVar(t); 00363 } 00364 00365 MVar& operator+=(const MVar& v){ 00366 if(type_ == Float){ 00367 if(v.type_ == Float){ 00368 data_.f += v.data_.f; 00369 return *this; 00370 } 00371 else if(v.type_ & DefinedNumericMask){ 00372 data_.f += v.toDouble(); 00373 return *this; 00374 } 00375 } 00376 00377 return addA(v); 00378 } 00379 00380 MVar& addA(const MVar& v); 00381 00382 MVar operator+(const MVar& v) const{ 00383 MVar ret(*this); 00384 return ret += v; 00385 } 00386 00387 template<typename T> 00388 MVar operator+(T& x) const{ 00389 MVar ret(*this); 00390 return ret += MVar(x); 00391 } 00392 00393 MVar operator+(uint32_t x) const{ 00394 MVar ret(*this); 00395 return ret += MVar(x); 00396 } 00397 00398 MVar operator+(int32_t x) const{ 00399 MVar ret(*this); 00400 return ret += MVar(x); 00401 } 00402 00403 MVar operator+(uint64_t x) const{ 00404 MVar ret(*this); 00405 return ret += MVar(x); 00406 } 00407 00408 MVar operator+(int64_t x) const{ 00409 MVar ret(*this); 00410 return ret += MVar(x); 00411 } 00412 00413 #if defined (__i386__) || defined (__APPLE__) 00414 00415 MVar operator+(unsigned long int x) const{ 00416 MVar ret(*this); 00417 return ret += MVar(x); 00418 } 00419 00420 MVar operator+(long int x) const{ 00421 MVar ret(*this); 00422 return ret += MVar(x); 00423 } 00424 00425 #endif 00426 00427 MVar operator+(double x) const{ 00428 MVar ret(*this); 00429 return ret += MVar(x); 00430 } 00431 00432 MVar operator++(int){ 00433 MVar ret(*this); 00434 *this += 1; 00435 return ret; 00436 } 00437 00438 MVar& operator++(){ 00439 return *this += 1; 00440 } 00441 00442 MVar& operator-=(const MVar& v){ 00443 if(type_ == Float){ 00444 if(v.type_ == Float){ 00445 data_.f -= v.data_.f; 00446 return *this; 00447 } 00448 else if(v.type_ & DefinedNumericMask){ 00449 data_.f -= v.toDouble(); 00450 return *this; 00451 } 00452 } 00453 00454 return subA(v); 00455 } 00456 00457 MVar& subA(const MVar& v); 00458 00459 MVar operator-(const MVar& v) const{ 00460 MVar ret(*this); 00461 return ret -= v; 00462 } 00463 00464 template<typename T> 00465 MVar operator-(T& x) const{ 00466 MVar ret(*this); 00467 return ret -= MVar(x); 00468 } 00469 00470 MVar operator-(uint32_t x) const{ 00471 MVar ret(*this); 00472 return ret -= MVar(x); 00473 } 00474 00475 MVar operator-(int32_t x) const{ 00476 MVar ret(*this); 00477 return ret -= MVar(x); 00478 } 00479 00480 MVar operator-(uint64_t x) const{ 00481 MVar ret(*this); 00482 return ret -= MVar(x); 00483 } 00484 00485 MVar operator-(int64_t x) const{ 00486 MVar ret(*this); 00487 return ret -= MVar(x); 00488 } 00489 00490 #if defined (__i386__) || defined (__APPLE__) 00491 00492 MVar operator-(unsigned long int x) const{ 00493 MVar ret(*this); 00494 return ret -= MVar(x); 00495 } 00496 00497 MVar operator-(long int x) const{ 00498 MVar ret(*this); 00499 return ret -= MVar(x); 00500 } 00501 00502 #endif 00503 00504 MVar operator-(double x) const{ 00505 MVar ret(*this); 00506 return ret -= MVar(x); 00507 } 00508 00509 MVar operator--(int){ 00510 MVar ret(*this); 00511 *this -= 1; 00512 return ret; 00513 } 00514 00515 MVar& operator--(){ 00516 return *this -= 1; 00517 } 00518 00519 MVar operator-() const{ 00520 if(type_ == Float){ 00521 return -data_.f; 00522 } 00523 00524 return neg(); 00525 } 00526 00527 MVar neg() const; 00528 00529 MVar& operator*=(const MVar& v){ 00530 if(type_ == Float){ 00531 if(v.type_ == Float){ 00532 data_.f *= v.data_.f; 00533 return *this; 00534 } 00535 else if(v.type_ & DefinedNumericMask){ 00536 data_.f *= v.toDouble(); 00537 return *this; 00538 } 00539 } 00540 00541 return mulA(v); 00542 } 00543 00544 MVar& mulA(const MVar& v); 00545 00546 MVar operator*(const MVar& v) const{ 00547 MVar ret(*this); 00548 return ret *= v; 00549 } 00550 00551 template<typename T> 00552 MVar operator*(T& x) const{ 00553 MVar ret(*this); 00554 return ret *= MVar(x); 00555 } 00556 00557 MVar operator*(uint32_t x) const{ 00558 MVar ret(*this); 00559 return ret *= MVar(x); 00560 } 00561 00562 MVar operator*(int32_t x) const{ 00563 MVar ret(*this); 00564 return ret *= MVar(x); 00565 } 00566 00567 MVar operator*(uint64_t x) const{ 00568 MVar ret(*this); 00569 return ret *= MVar(x); 00570 } 00571 00572 MVar operator*(int64_t x) const{ 00573 MVar ret(*this); 00574 return ret *= MVar(x); 00575 } 00576 00577 #if defined (__i386__) || defined (__APPLE__) 00578 00579 MVar operator*(unsigned long int x) const{ 00580 MVar ret(*this); 00581 return ret *= MVar(x); 00582 } 00583 00584 MVar operator*(long int x) const{ 00585 MVar ret(*this); 00586 return ret *= MVar(x); 00587 } 00588 00589 #endif 00590 00591 MVar operator*(double x) const{ 00592 MVar ret(*this); 00593 return ret *= MVar(x); 00594 } 00595 00596 MVar& operator/=(const MVar& v){ 00597 if(type_ == Float){ 00598 if(v.type_ == Float){ 00599 data_.f /= v.data_.f; 00600 return *this; 00601 } 00602 else if(v.type_ & DefinedNumericMask){ 00603 data_.f /= v.toDouble(); 00604 return *this; 00605 } 00606 } 00607 00608 return divA(v); 00609 } 00610 00611 MVar& divA(const MVar& v); 00612 00613 MVar operator/(const MVar& v) const{ 00614 MVar ret(*this); 00615 return ret /= v; 00616 } 00617 00618 template<typename T> 00619 MVar operator/(T& x) const{ 00620 MVar ret(*this); 00621 return ret /= MVar(x); 00622 } 00623 00624 MVar operator/(uint32_t x) const{ 00625 MVar ret(*this); 00626 return ret /= MVar(x); 00627 } 00628 00629 MVar operator/(int32_t x) const{ 00630 MVar ret(*this); 00631 return ret /= MVar(x); 00632 } 00633 00634 MVar operator/(uint64_t x) const{ 00635 MVar ret(*this); 00636 return ret /= MVar(x); 00637 } 00638 00639 MVar operator/(int64_t x) const{ 00640 MVar ret(*this); 00641 return ret /= MVar(x); 00642 } 00643 00644 MVar operator/(double x) const{ 00645 MVar ret(*this); 00646 return ret /= MVar(x); 00647 } 00648 00649 #if defined (__i386__) || defined (__APPLE__) 00650 00651 MVar operator/(unsigned long int x) const{ 00652 MVar ret(*this); 00653 return ret /= MVar(x); 00654 } 00655 00656 MVar operator/(long int x) const{ 00657 MVar ret(*this); 00658 return ret /= MVar(x); 00659 } 00660 00661 #endif 00662 00663 bool operator<(const MVar& v) const{ 00664 if(type_ == Float){ 00665 if(v.type_ == Float){ 00666 return data_.f < v.data_.f; 00667 } 00668 else if(v.type_ & DefinedNumericMask){ 00669 return data_.f < v.toDouble(); 00670 } 00671 00672 return false; 00673 } 00674 00675 return lt(v); 00676 } 00677 00678 bool lt(const MVar& v) const; 00679 00680 template<typename T> 00681 bool operator<(const T& t) const{ 00682 return *this < MVar(t); 00683 } 00684 00685 bool operator>(const MVar& v) const{ 00686 if(type_ == Float){ 00687 if(v.type_ == Float){ 00688 return data_.f > v.data_.f; 00689 } 00690 else if(v.type_ & DefinedNumericMask){ 00691 return data_.f > v.toDouble(); 00692 } 00693 00694 return false; 00695 } 00696 00697 return gt(v); 00698 } 00699 00700 bool gt(const MVar& v) const; 00701 00702 template<typename T> 00703 bool operator>(const T& t) const{ 00704 return *this > MVar(t); 00705 } 00706 00707 bool operator<=(const MVar& v) const{ 00708 if(type_ == Float){ 00709 if(v.type_ == Float){ 00710 return data_.f <= v.data_.f; 00711 } 00712 else if(v.type_ & DefinedNumericMask){ 00713 return data_.f <= v.toDouble(); 00714 } 00715 00716 return false; 00717 } 00718 00719 return le(v); 00720 } 00721 00722 bool le(const MVar& v) const; 00723 00724 template<typename T> 00725 bool operator<=(const T& t) const{ 00726 return *this <= MVar(t); 00727 } 00728 00729 bool operator>=(const MVar& v) const{ 00730 if(type_ == Float){ 00731 if(v.type_ == Float){ 00732 return data_.f >= v.data_.f; 00733 } 00734 else if(v.type_ & DefinedNumericMask){ 00735 return data_.f >= v.toDouble(); 00736 } 00737 00738 return false; 00739 } 00740 00741 return ge(v); 00742 } 00743 00744 bool ge(const MVar& v) const; 00745 00746 template<typename T> 00747 bool operator>=(const T& t) const{ 00748 return *this >= MVar(t); 00749 } 00750 00751 bool operator==(const MVar& v) const{ 00752 if(type_ == Float){ 00753 if(v.type_ == Float){ 00754 return data_.f == v.data_.f; 00755 } 00756 else if(v.type_ & DefinedNumericMask){ 00757 return data_.f == v.toDouble(); 00758 } 00759 00760 return false; 00761 } 00762 00763 return eq(v); 00764 } 00765 00766 bool eq(const MVar& v) const; 00767 00768 bool operator==(const MStr& s) const; 00769 00770 template<typename T> 00771 bool operator==(const T& t) const{ 00772 return *this == MVar(t); 00773 } 00774 00775 bool operator==(const std::string& s) const{ 00776 return *this == MStr(s); 00777 } 00778 00779 bool operator==(const char* s) const{ 00780 return *this == MStr(s); 00781 } 00782 00783 bool operator!=(const MVar& v) const{ 00784 return !(*this == v); 00785 } 00786 00787 bool operator!=(const MStr& s) const; 00788 00789 template<typename T> 00790 bool operator!=(const T& t) const{ 00791 return *this != MVar(t); 00792 } 00793 00794 bool operator!=(const std::string& s) const{ 00795 return *this != MStr(s); 00796 } 00797 00798 bool operator!=(const char* s) const{ 00799 return *this != MStr(s); 00800 } 00801 00802 const MVar& operator[](const MVar& key) const; 00803 00804 MVar& operator[](const MVar& key); 00805 00806 template<typename T> 00807 const MVar& operator[](const T& key) const{ 00808 return (*this)[MVar(key)]; 00809 } 00810 00811 template<typename T> 00812 MVar& operator[](const T& key){ 00813 return (*this)[MVar(key)]; 00814 } 00815 00816 bool operator!() const{ 00817 return !toBool(); 00818 } 00819 00820 MVar& operator%=(const MVar& v); 00821 00822 MVar operator%(const MVar& v) const{ 00823 MVar ret(*this); 00824 return ret %= v; 00825 } 00826 00827 template<typename T> 00828 MVar operator%(const T& t) const{ 00829 MVar ret(*this); 00830 return ret %= MVar(t); 00831 } 00832 00833 MVar operator%(uint32_t x) const{ 00834 MVar ret(*this); 00835 return ret %= MVar(x); 00836 } 00837 00838 MVar operator%(int32_t x) const{ 00839 MVar ret(*this); 00840 return ret %= MVar(x); 00841 } 00842 00843 MVar operator%(uint64_t x) const{ 00844 MVar ret(*this); 00845 return ret %= MVar(x); 00846 } 00847 00848 MVar operator%(int64_t x) const{ 00849 MVar ret(*this); 00850 return ret %= MVar(x); 00851 } 00852 00853 #if defined (__i386__) || defined (__APPLE__) 00854 00855 MVar operator%(unsigned long int x) const{ 00856 MVar ret(*this); 00857 return ret %= MVar(x); 00858 } 00859 00860 MVar operator%(long int x) const{ 00861 MVar ret(*this); 00862 return ret %= MVar(x); 00863 } 00864 00865 #endif 00866 00867 MVar operator%(double x) const{ 00868 MVar ret(*this); 00869 return ret %= MVar(x); 00870 } 00871 00872 MVar& operator<<(const MVar& v){ 00873 push_back(v); 00874 return *this; 00875 } 00876 00877 template<typename T> 00878 MVar& operator<<(const T& x){ 00879 push_back(MVar(x)); 00880 return *this; 00881 } 00882 00883 typedef void (MVar::*BoolType_)() const; 00884 00885 void boolStub_() const{} 00886 00887 operator BoolType_() const { 00888 return toBool() ? &MVar::boolStub_ : 0; 00889 } 00890 00891 bool isDefined() const; 00892 00893 bool isNumeric() const{ 00894 return type_ & NumericMask; 00895 } 00896 00897 int isRational() const; 00898 00899 bool isReal() const; 00900 00901 Type type() const{ 00902 return type_; 00903 } 00904 00905 MVar& get(const MVar& key, bool errorOnExists=false); 00906 00907 MVar& operator()(const MVar& key){ 00908 return get(key); 00909 } 00910 00914 mvec keys(bool all=true, bool indexed=false) const; 00915 00919 size_t size() const; 00920 00924 size_t mapSize() const; 00925 00926 bool isMapEmpty() const; 00927 00931 bool isSeqEmpty() const; 00932 00936 bool isEmpty() const; 00937 00941 size_t span() const; 00942 00943 bool toBool() const; 00944 00945 void setBinary(const char* buf, 00946 size_t pos, 00947 size_t count, 00948 Type t=String); 00949 00950 size_t getBinary(char* buf, size_t pos, size_t count) const; 00951 00952 size_t getBinary(char* buf, size_t pos) const; 00953 00954 size_t binarySize() const; 00955 00959 bool hasKey(const MVar& key) const; 00960 00965 bool keyValue(const MVar& key, const MVar& value) const; 00966 00967 void setType(Type t); 00968 00969 MVar& setHead(const MVar& v, Type t=String); 00970 00971 void clearHead(); 00972 00973 MVar head() const; 00974 00975 MVar& back(); 00976 00977 const MVar& back() const; 00978 00979 void pushBack(const MVar& v); 00980 00981 void push_back(const MVar& v){ 00982 pushBack(v); 00983 } 00984 00985 void push(const MVar& v){ 00986 pushBack(v); 00987 } 00988 00989 void pushFront(const MVar& v); 00990 00991 void push_front(const MVar& v){ 00992 pushFront(v); 00993 } 00994 00995 MVar popBack(); 00996 00997 void pop_back(); 00998 00999 MVar popFront(); 01000 01001 void pop_front(); 01002 01003 void pop(){ 01004 pop_back(); 01005 } 01006 01007 void insert(int64_t pos, const MVar& value); 01008 01009 MVar& add(const MVar& value){ 01010 pushBack(value); 01011 return *this; 01012 } 01013 01014 MVar& add(const MVar& key, const MVar& value){ 01015 get(key) = value; 01016 return *this; 01017 } 01018 01023 const MVar& uget(const MVar& key, const MVar& def=undef) const; 01024 01030 int64_t index(const MVar& value, int64_t start=0, int64_t end=-1) const; 01031 01032 void erase(const MVar& key); 01033 01037 void clearSeq(); 01038 01039 void clearMap(); 01040 01041 void clear(){ 01042 clearSeq(); 01043 clearMap(); 01044 } 01045 01046 void merge(const MVar& v); 01047 01048 void outerMerge(const MVar& v); 01049 01050 static MVar fromStr(const mstr& str, bool literal=true, bool exact=false); 01051 01052 static MStr itp(const MStr& str, const mvec& vars); 01053 01054 bool hasVector() const; 01055 01056 bool hasList() const; 01057 01061 void indexMap(bool flag); 01062 01068 int64_t keyIndex(const mstr& key); 01069 01070 bool isString() const{ 01071 return type_ == String; 01072 } 01073 01074 bool isStringPtr() const; 01075 01082 mvec split(const mstr& delimiter, int maxTokens=-1) const; 01083 01087 mstr join(const mstr& delimiter) const; 01088 01092 MVar& unite(); 01093 01097 MVar& unite(const MVar& v, bool outer=false); 01098 01102 MVar& intersect(const MVar& v, bool outer=false); 01103 01107 MVar& complement(const MVar& v); 01108 01112 bool subsumesData(const MVar& v) const; 01113 01117 MVar clone() const; 01118 01123 MVar& unlink(); 01124 01129 bool isCodeData() const{ 01130 return type_ & CodeDataMask; 01131 } 01132 01137 void setCodeData(bool flag); 01138 01145 enum ToNodeType{ 01146 ToNodeTop, 01147 ToNodeOne, 01148 ToNodeAll, 01149 ToNodeNone 01150 }; 01151 01157 mnode toNode(ToNodeType type=ToNodeTop) const; 01158 01162 bool isSymbolic() const; 01163 01167 bool isFunction() const; 01168 01172 bool isFunction(const mstr& f) const; 01173 01177 bool isFunction(const mstr& f, size_t args) const; 01178 01183 bool isFunction(const mstr& f, size_t argsMin, size_t argsMax) const; 01184 01188 bool isSymbol() const; 01189 01193 bool isSymbol(const mstr& name) const; 01194 01195 void convertConstant(); 01196 01200 static double inf(); 01201 01205 static double negInf(); 01206 01210 static double nan(); 01211 01215 static double min(); 01216 01220 static double max(); 01221 01226 static double epsilon(); 01227 01228 private: 01229 void span_(size_t& s) const; 01230 01231 Type type_; 01232 uint8_t flags_; 01233 01234 union{ 01235 double f; 01236 int64_t i; 01237 mstr* s; 01238 MRational* r; 01239 MReal* x; 01240 void* p; 01241 MObjectBase* o; 01242 }data_; 01243 01244 union{ 01245 mvec* v; 01246 mlist* l; 01247 }vl_; 01248 01249 mmap* map_; 01250 }; 01251 01252 std::ostream& operator<<(std::ostream& ostr, const MVar& v); 01253 01254 std::istream& operator>>(std::istream& is, MVar& v); 01255 01256 template<typename T> 01257 inline bool operator<(const T& v1, const MVar& v2){ 01258 return MVar(v1) < v2; 01259 } 01260 01261 template<typename T> 01262 inline bool operator>(const T& v1, const MVar& v2){ 01263 return MVar(v1) > v2; 01264 } 01265 01266 template<typename T> 01267 inline bool operator<=(const T& v1, const MVar& v2){ 01268 return MVar(v1) <= v2; 01269 } 01270 01271 template<typename T> 01272 inline bool operator>=(const T& v1, const MVar& v2){ 01273 return MVar(v1) >= v2; 01274 } 01275 01276 template<typename T> 01277 inline bool operator==(const T& v1, const MVar& v2){ 01278 return MVar(v1) == v2; 01279 } 01280 01281 template<typename T> 01282 inline bool operator!=(const T& v1, const MVar& v2){ 01283 return MVar(v1) != v2; 01284 } 01285 01286 template<typename T> 01287 inline MVar operator+(const T& v1, const MVar& v2){ 01288 MVar ret(v1); 01289 return ret += v2; 01290 } 01291 01292 template<typename T> 01293 inline MVar operator-(const T& v1, const MVar& v2){ 01294 MVar ret(v1); 01295 return ret -= v2; 01296 } 01297 01298 template<typename T> 01299 inline MVar operator*(const T& v1, const MVar& v2){ 01300 MVar ret(v1); 01301 return ret *= v2; 01302 } 01303 01304 template<typename T> 01305 inline MVar operator/(const T& v1, const MVar& v2){ 01306 MVar ret(v1); 01307 return ret /= v2; 01308 } 01309 01310 template<typename T> 01311 inline MVar operator%(const T& v1, const MVar& v2){ 01312 MVar ret(v1); 01313 return ret %= v2; 01314 } 01315 01316 typedef MVar mvar; 01317 01318 typedef MVar mdist; 01319 01320 } // end namespace Meta 01321 01322 #endif // ANDROMETA_M_VAR_H
1.7.6.1