Changeset 10399 in webkit for trunk/JavaScriptCore
- Timestamp:
- Aug 30, 2005, 4:56:15 PM (20 years ago)
- Location:
- trunk/JavaScriptCore
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/ChangeLog
r10354 r10399 1 2005-08-30 Darin Adler <[email protected]> 2 3 Reviewed by John Sullivan. 4 5 - fixed http://bugzilla.opendarwin.org/show_bug.cgi?id=4758 6 unify SharedPtr in WebCore and JavaScriptCore 7 8 * kjs/shared_ptr.h: Updated namespace to KXMLCore instead of kxhmlcore. 9 Made a few small improvements to use local variables a bit more and added 10 an "operator int" to reduce the chance that we'll convert a SharedPtr to 11 an int by accident. Also made the == operators normal functions rather than 12 friend functions, added a couple of comemnts. 13 14 * kjs/function.h: Updated for namespace change. 15 * kjs/function.cpp: Ditto. 16 * kjs/function_object.cpp: Ditto. 17 * kjs/internal.h: Ditto. 18 * kjs/internal.cpp: Ditto. 19 * kjs/nodes.h: Ditto. 20 * kjs/nodes2string.cpp: Ditto. 21 1 22 2005-08-26 Maciej Stachowiak <[email protected]> 2 23 -
trunk/JavaScriptCore/kjs/function.cpp
r10352 r10399 44 44 #endif 45 45 46 using namespace kxmlcore;46 using namespace KXMLCore; 47 47 48 48 namespace KJS { -
trunk/JavaScriptCore/kjs/function.h
r10352 r10399 83 83 virtual Completion execute(ExecState *exec); 84 84 CodeType codeType() const { return FunctionCode; } 85 kxmlcore::SharedPtr<FunctionBodyNode> body;85 KXMLCore::SharedPtr<FunctionBodyNode> body; 86 86 87 87 virtual const ClassInfo *classInfo() const { return &info; } -
trunk/JavaScriptCore/kjs/function_object.cpp
r10352 r10399 35 35 36 36 using namespace KJS; 37 using namespace kxmlcore;37 using namespace KXMLCore; 38 38 39 39 // ------------------------------ FunctionPrototypeImp ------------------------- -
trunk/JavaScriptCore/kjs/internal.cpp
r10354 r10399 54 54 extern int kjsyyparse(); 55 55 56 using namespace kxmlcore;56 using namespace KXMLCore; 57 57 58 58 namespace KJS { -
trunk/JavaScriptCore/kjs/internal.h
r10354 r10399 197 197 class Parser { 198 198 public: 199 static kxmlcore::SharedPtr<ProgramNode> parse(const UString &sourceURL, int startingLineNumber,199 static KXMLCore::SharedPtr<ProgramNode> parse(const UString &sourceURL, int startingLineNumber, 200 200 const UChar *code, unsigned int length, int *sourceId = 0, 201 201 int *errLine = 0, UString *errMsg = 0); -
trunk/JavaScriptCore/kjs/nodes.h
r10354 r10399 205 205 virtual void streamTo(SourceStream &s) const; 206 206 private: 207 kxmlcore::SharedPtr<Node> group;207 KXMLCore::SharedPtr<Node> group; 208 208 }; 209 209 … … 218 218 private: 219 219 friend class ArrayNode; 220 kxmlcore::SharedPtr<ElementNode> list;220 KXMLCore::SharedPtr<ElementNode> list; 221 221 int elision; 222 kxmlcore::SharedPtr<Node> node;222 KXMLCore::SharedPtr<Node> node; 223 223 }; 224 224 … … 233 233 virtual void streamTo(SourceStream &s) const; 234 234 private: 235 kxmlcore::SharedPtr<ElementNode> element;235 KXMLCore::SharedPtr<ElementNode> element; 236 236 int elision; 237 237 bool opt; … … 249 249 private: 250 250 friend class ObjectLiteralNode; 251 kxmlcore::SharedPtr<PropertyNode> name;252 kxmlcore::SharedPtr<Node> assign;253 kxmlcore::SharedPtr<PropertyValueNode> list;251 KXMLCore::SharedPtr<PropertyNode> name; 252 KXMLCore::SharedPtr<Node> assign; 253 KXMLCore::SharedPtr<PropertyValueNode> list; 254 254 }; 255 255 … … 261 261 virtual void streamTo(SourceStream &s) const; 262 262 private: 263 kxmlcore::SharedPtr<PropertyValueNode> list;263 KXMLCore::SharedPtr<PropertyValueNode> list; 264 264 }; 265 265 … … 282 282 virtual void streamTo(SourceStream &s) const; 283 283 private: 284 kxmlcore::SharedPtr<Node> expr1;285 kxmlcore::SharedPtr<Node> expr2;284 KXMLCore::SharedPtr<Node> expr1; 285 KXMLCore::SharedPtr<Node> expr2; 286 286 }; 287 287 … … 293 293 virtual void streamTo(SourceStream &s) const; 294 294 private: 295 kxmlcore::SharedPtr<Node> expr;295 KXMLCore::SharedPtr<Node> expr; 296 296 Identifier ident; 297 297 }; … … 308 308 private: 309 309 friend class ArgumentsNode; 310 kxmlcore::SharedPtr<ArgumentListNode> list;311 kxmlcore::SharedPtr<Node> expr;310 KXMLCore::SharedPtr<ArgumentListNode> list; 311 KXMLCore::SharedPtr<Node> expr; 312 312 }; 313 313 … … 321 321 virtual void streamTo(SourceStream &s) const; 322 322 private: 323 kxmlcore::SharedPtr<ArgumentListNode> list;323 KXMLCore::SharedPtr<ArgumentListNode> list; 324 324 }; 325 325 … … 331 331 virtual void streamTo(SourceStream &s) const; 332 332 private: 333 kxmlcore::SharedPtr<Node> expr;334 kxmlcore::SharedPtr<ArgumentsNode> args;333 KXMLCore::SharedPtr<Node> expr; 334 KXMLCore::SharedPtr<ArgumentsNode> args; 335 335 }; 336 336 … … 341 341 virtual void streamTo(SourceStream &s) const; 342 342 private: 343 kxmlcore::SharedPtr<Node> expr;344 kxmlcore::SharedPtr<ArgumentsNode> args;343 KXMLCore::SharedPtr<Node> expr; 344 KXMLCore::SharedPtr<ArgumentsNode> args; 345 345 }; 346 346 … … 352 352 private: 353 353 Identifier ident; 354 kxmlcore::SharedPtr<ArgumentsNode> args;354 KXMLCore::SharedPtr<ArgumentsNode> args; 355 355 }; 356 356 … … 361 361 virtual void streamTo(SourceStream &s) const; 362 362 protected: 363 kxmlcore::SharedPtr<Node> base;364 kxmlcore::SharedPtr<Node> subscript;365 kxmlcore::SharedPtr<ArgumentsNode> args;363 KXMLCore::SharedPtr<Node> base; 364 KXMLCore::SharedPtr<Node> subscript; 365 KXMLCore::SharedPtr<ArgumentsNode> args; 366 366 }; 367 367 … … 378 378 virtual void streamTo(SourceStream &s) const; 379 379 protected: 380 kxmlcore::SharedPtr<Node> base;380 KXMLCore::SharedPtr<Node> base; 381 381 Identifier ident; 382 kxmlcore::SharedPtr<ArgumentsNode> args;382 KXMLCore::SharedPtr<ArgumentsNode> args; 383 383 }; 384 384 … … 395 395 virtual void streamTo(SourceStream &s) const; 396 396 private: 397 kxmlcore::SharedPtr<Node> expr;397 KXMLCore::SharedPtr<Node> expr; 398 398 Operator oper; 399 399 }; … … 405 405 virtual void streamTo(SourceStream &s) const; 406 406 private: 407 kxmlcore::SharedPtr<Node> expr;407 KXMLCore::SharedPtr<Node> expr; 408 408 }; 409 409 … … 414 414 virtual void streamTo(SourceStream &s) const; 415 415 private: 416 kxmlcore::SharedPtr<Node> expr;416 KXMLCore::SharedPtr<Node> expr; 417 417 }; 418 418 … … 423 423 virtual void streamTo(SourceStream &s) const; 424 424 private: 425 kxmlcore::SharedPtr<Node> expr;425 KXMLCore::SharedPtr<Node> expr; 426 426 }; 427 427 … … 433 433 private: 434 434 Operator oper; 435 kxmlcore::SharedPtr<Node> expr;435 KXMLCore::SharedPtr<Node> expr; 436 436 }; 437 437 … … 442 442 virtual void streamTo(SourceStream &s) const; 443 443 private: 444 kxmlcore::SharedPtr<Node> expr;444 KXMLCore::SharedPtr<Node> expr; 445 445 }; 446 446 … … 451 451 virtual void streamTo(SourceStream &s) const; 452 452 private: 453 kxmlcore::SharedPtr<Node> expr;453 KXMLCore::SharedPtr<Node> expr; 454 454 }; 455 455 … … 460 460 virtual void streamTo(SourceStream &s) const; 461 461 private: 462 kxmlcore::SharedPtr<Node> expr;462 KXMLCore::SharedPtr<Node> expr; 463 463 }; 464 464 … … 469 469 virtual void streamTo(SourceStream &s) const; 470 470 private: 471 kxmlcore::SharedPtr<Node> expr;471 KXMLCore::SharedPtr<Node> expr; 472 472 }; 473 473 … … 478 478 virtual void streamTo(SourceStream &s) const; 479 479 private: 480 kxmlcore::SharedPtr<Node> term1;481 kxmlcore::SharedPtr<Node> term2;480 KXMLCore::SharedPtr<Node> term1; 481 KXMLCore::SharedPtr<Node> term2; 482 482 char oper; 483 483 }; … … 489 489 virtual void streamTo(SourceStream &s) const; 490 490 private: 491 kxmlcore::SharedPtr<Node> term1;492 kxmlcore::SharedPtr<Node> term2;491 KXMLCore::SharedPtr<Node> term1; 492 KXMLCore::SharedPtr<Node> term2; 493 493 char oper; 494 494 }; … … 501 501 virtual void streamTo(SourceStream &s) const; 502 502 private: 503 kxmlcore::SharedPtr<Node> term1;504 kxmlcore::SharedPtr<Node> term2;503 KXMLCore::SharedPtr<Node> term1; 504 KXMLCore::SharedPtr<Node> term2; 505 505 Operator oper; 506 506 }; … … 513 513 virtual void streamTo(SourceStream &s) const; 514 514 private: 515 kxmlcore::SharedPtr<Node> expr1;516 kxmlcore::SharedPtr<Node> expr2;515 KXMLCore::SharedPtr<Node> expr1; 516 KXMLCore::SharedPtr<Node> expr2; 517 517 Operator oper; 518 518 }; … … 525 525 virtual void streamTo(SourceStream &s) const; 526 526 private: 527 kxmlcore::SharedPtr<Node> expr1;528 kxmlcore::SharedPtr<Node> expr2;527 KXMLCore::SharedPtr<Node> expr1; 528 KXMLCore::SharedPtr<Node> expr2; 529 529 Operator oper; 530 530 }; … … 537 537 virtual void streamTo(SourceStream &s) const; 538 538 private: 539 kxmlcore::SharedPtr<Node> expr1;540 kxmlcore::SharedPtr<Node> expr2;539 KXMLCore::SharedPtr<Node> expr1; 540 KXMLCore::SharedPtr<Node> expr2; 541 541 Operator oper; 542 542 }; … … 552 552 virtual void streamTo(SourceStream &s) const; 553 553 private: 554 kxmlcore::SharedPtr<Node> expr1;555 kxmlcore::SharedPtr<Node> expr2;554 KXMLCore::SharedPtr<Node> expr1; 555 KXMLCore::SharedPtr<Node> expr2; 556 556 Operator oper; 557 557 }; … … 567 567 virtual void streamTo(SourceStream &s) const; 568 568 private: 569 kxmlcore::SharedPtr<Node> logical;570 kxmlcore::SharedPtr<Node> expr1;571 kxmlcore::SharedPtr<Node> expr2;569 KXMLCore::SharedPtr<Node> logical; 570 KXMLCore::SharedPtr<Node> expr1; 571 KXMLCore::SharedPtr<Node> expr2; 572 572 }; 573 573 … … 581 581 Identifier m_ident; 582 582 Operator m_oper; 583 kxmlcore::SharedPtr<Node> m_right;583 KXMLCore::SharedPtr<Node> m_right; 584 584 }; 585 585 … … 591 591 virtual void streamTo(SourceStream &s) const; 592 592 protected: 593 kxmlcore::SharedPtr<Node> m_base;594 kxmlcore::SharedPtr<Node> m_subscript;593 KXMLCore::SharedPtr<Node> m_base; 594 KXMLCore::SharedPtr<Node> m_subscript; 595 595 Operator m_oper; 596 kxmlcore::SharedPtr<Node> m_right;596 KXMLCore::SharedPtr<Node> m_right; 597 597 }; 598 598 … … 604 604 virtual void streamTo(SourceStream &s) const; 605 605 protected: 606 kxmlcore::SharedPtr<Node> m_base;606 KXMLCore::SharedPtr<Node> m_base; 607 607 Identifier m_ident; 608 608 Operator m_oper; 609 kxmlcore::SharedPtr<Node> m_right;609 KXMLCore::SharedPtr<Node> m_right; 610 610 }; 611 611 … … 616 616 virtual void streamTo(SourceStream &s) const; 617 617 private: 618 kxmlcore::SharedPtr<Node> expr1;619 kxmlcore::SharedPtr<Node> expr2;618 KXMLCore::SharedPtr<Node> expr1; 619 KXMLCore::SharedPtr<Node> expr2; 620 620 }; 621 621 … … 630 630 private: 631 631 friend class CaseClauseNode; 632 kxmlcore::SharedPtr<StatementNode> statement;633 kxmlcore::SharedPtr<StatListNode> list;632 KXMLCore::SharedPtr<StatementNode> statement; 633 KXMLCore::SharedPtr<StatListNode> list; 634 634 }; 635 635 … … 640 640 virtual void streamTo(SourceStream &s) const; 641 641 private: 642 kxmlcore::SharedPtr<Node> expr;642 KXMLCore::SharedPtr<Node> expr; 643 643 }; 644 644 … … 653 653 Type varType; 654 654 Identifier ident; 655 kxmlcore::SharedPtr<AssignExprNode> init;655 KXMLCore::SharedPtr<AssignExprNode> init; 656 656 }; 657 657 … … 668 668 friend class ForNode; 669 669 friend class VarStatementNode; 670 kxmlcore::SharedPtr<VarDeclListNode> list;671 kxmlcore::SharedPtr<VarDeclNode> var;670 KXMLCore::SharedPtr<VarDeclListNode> list; 671 KXMLCore::SharedPtr<VarDeclNode> var; 672 672 }; 673 673 … … 679 679 virtual void streamTo(SourceStream &s) const; 680 680 private: 681 kxmlcore::SharedPtr<VarDeclListNode> list;681 KXMLCore::SharedPtr<VarDeclListNode> list; 682 682 }; 683 683 … … 689 689 virtual void streamTo(SourceStream &s) const; 690 690 protected: 691 kxmlcore::SharedPtr<SourceElementsNode> source;691 KXMLCore::SharedPtr<SourceElementsNode> source; 692 692 }; 693 693 … … 705 705 virtual void streamTo(SourceStream &s) const; 706 706 private: 707 kxmlcore::SharedPtr<Node> expr;707 KXMLCore::SharedPtr<Node> expr; 708 708 }; 709 709 … … 716 716 virtual void streamTo(SourceStream &s) const; 717 717 private: 718 kxmlcore::SharedPtr<Node> expr;719 kxmlcore::SharedPtr<StatementNode> statement1;720 kxmlcore::SharedPtr<StatementNode> statement2;718 KXMLCore::SharedPtr<Node> expr; 719 KXMLCore::SharedPtr<StatementNode> statement1; 720 KXMLCore::SharedPtr<StatementNode> statement2; 721 721 }; 722 722 … … 728 728 virtual void streamTo(SourceStream &s) const; 729 729 private: 730 kxmlcore::SharedPtr<StatementNode> statement;731 kxmlcore::SharedPtr<Node> expr;730 KXMLCore::SharedPtr<StatementNode> statement; 731 KXMLCore::SharedPtr<Node> expr; 732 732 }; 733 733 … … 739 739 virtual void streamTo(SourceStream &s) const; 740 740 private: 741 kxmlcore::SharedPtr<Node> expr;742 kxmlcore::SharedPtr<StatementNode> statement;741 KXMLCore::SharedPtr<Node> expr; 742 KXMLCore::SharedPtr<StatementNode> statement; 743 743 }; 744 744 … … 753 753 virtual void streamTo(SourceStream &s) const; 754 754 private: 755 kxmlcore::SharedPtr<Node> expr1;756 kxmlcore::SharedPtr<Node> expr2;757 kxmlcore::SharedPtr<Node> expr3;758 kxmlcore::SharedPtr<StatementNode> statement;755 KXMLCore::SharedPtr<Node> expr1; 756 KXMLCore::SharedPtr<Node> expr2; 757 KXMLCore::SharedPtr<Node> expr3; 758 KXMLCore::SharedPtr<StatementNode> statement; 759 759 }; 760 760 … … 768 768 private: 769 769 Identifier ident; 770 kxmlcore::SharedPtr<AssignExprNode> init;771 kxmlcore::SharedPtr<Node> lexpr;772 kxmlcore::SharedPtr<Node> expr;773 kxmlcore::SharedPtr<VarDeclNode> varDecl;774 kxmlcore::SharedPtr<StatementNode> statement;770 KXMLCore::SharedPtr<AssignExprNode> init; 771 KXMLCore::SharedPtr<Node> lexpr; 772 KXMLCore::SharedPtr<Node> expr; 773 KXMLCore::SharedPtr<VarDeclNode> varDecl; 774 KXMLCore::SharedPtr<StatementNode> statement; 775 775 }; 776 776 … … 801 801 virtual void streamTo(SourceStream &s) const; 802 802 private: 803 kxmlcore::SharedPtr<Node> value;803 KXMLCore::SharedPtr<Node> value; 804 804 }; 805 805 … … 811 811 virtual void streamTo(SourceStream &s) const; 812 812 private: 813 kxmlcore::SharedPtr<Node> expr;814 kxmlcore::SharedPtr<StatementNode> statement;813 KXMLCore::SharedPtr<Node> expr; 814 KXMLCore::SharedPtr<StatementNode> statement; 815 815 }; 816 816 … … 825 825 virtual void streamTo(SourceStream &s) const; 826 826 private: 827 kxmlcore::SharedPtr<Node> expr;828 kxmlcore::SharedPtr<StatListNode> list;827 KXMLCore::SharedPtr<Node> expr; 828 KXMLCore::SharedPtr<StatListNode> list; 829 829 }; 830 830 … … 842 842 private: 843 843 friend class CaseBlockNode; 844 kxmlcore::SharedPtr<CaseClauseNode> cl;845 kxmlcore::SharedPtr<ClauseListNode> nx;844 KXMLCore::SharedPtr<CaseClauseNode> cl; 845 KXMLCore::SharedPtr<ClauseListNode> nx; 846 846 }; 847 847 … … 854 854 virtual void streamTo(SourceStream &s) const; 855 855 private: 856 kxmlcore::SharedPtr<ClauseListNode> list1;857 kxmlcore::SharedPtr<CaseClauseNode> def;858 kxmlcore::SharedPtr<ClauseListNode> list2;856 KXMLCore::SharedPtr<ClauseListNode> list1; 857 KXMLCore::SharedPtr<CaseClauseNode> def; 858 KXMLCore::SharedPtr<ClauseListNode> list2; 859 859 }; 860 860 … … 866 866 virtual void streamTo(SourceStream &s) const; 867 867 private: 868 kxmlcore::SharedPtr<Node> expr;869 kxmlcore::SharedPtr<CaseBlockNode> block;868 KXMLCore::SharedPtr<Node> expr; 869 KXMLCore::SharedPtr<CaseBlockNode> block; 870 870 }; 871 871 … … 878 878 private: 879 879 Identifier label; 880 kxmlcore::SharedPtr<StatementNode> statement;880 KXMLCore::SharedPtr<StatementNode> statement; 881 881 }; 882 882 … … 887 887 virtual void streamTo(SourceStream &s) const; 888 888 private: 889 kxmlcore::SharedPtr<Node> expr;889 KXMLCore::SharedPtr<Node> expr; 890 890 }; 891 891 … … 899 899 private: 900 900 Identifier ident; 901 kxmlcore::SharedPtr<StatementNode> block;901 KXMLCore::SharedPtr<StatementNode> block; 902 902 }; 903 903 … … 909 909 virtual void streamTo(SourceStream &s) const; 910 910 private: 911 kxmlcore::SharedPtr<StatementNode> block;911 KXMLCore::SharedPtr<StatementNode> block; 912 912 }; 913 913 … … 924 924 virtual void streamTo(SourceStream &s) const; 925 925 private: 926 kxmlcore::SharedPtr<StatementNode> block;927 kxmlcore::SharedPtr<CatchNode> _catch;928 kxmlcore::SharedPtr<FinallyNode> _final;926 KXMLCore::SharedPtr<StatementNode> block; 927 KXMLCore::SharedPtr<CatchNode> _catch; 928 KXMLCore::SharedPtr<FinallyNode> _final; 929 929 }; 930 930 … … 943 943 friend class FuncExprNode; 944 944 Identifier id; 945 kxmlcore::SharedPtr<ParameterNode> next;945 KXMLCore::SharedPtr<ParameterNode> next; 946 946 }; 947 947 … … 965 965 private: 966 966 Identifier ident; 967 kxmlcore::SharedPtr<ParameterNode> param;968 kxmlcore::SharedPtr<FunctionBodyNode> body;967 KXMLCore::SharedPtr<ParameterNode> param; 968 KXMLCore::SharedPtr<FunctionBodyNode> body; 969 969 }; 970 970 … … 977 977 virtual void streamTo(SourceStream &s) const; 978 978 private: 979 kxmlcore::SharedPtr<ParameterNode> param;980 kxmlcore::SharedPtr<FunctionBodyNode> body;979 KXMLCore::SharedPtr<ParameterNode> param; 980 KXMLCore::SharedPtr<FunctionBodyNode> body; 981 981 }; 982 982 … … 994 994 private: 995 995 friend class BlockNode; 996 kxmlcore::SharedPtr<StatementNode> element; // 'this' element997 kxmlcore::SharedPtr<SourceElementsNode> elements; // pointer to next996 KXMLCore::SharedPtr<StatementNode> element; // 'this' element 997 KXMLCore::SharedPtr<SourceElementsNode> elements; // pointer to next 998 998 }; 999 999 -
trunk/JavaScriptCore/kjs/nodes2string.cpp
r10352 r10399 24 24 #include "nodes.h" 25 25 26 using namespace kxmlcore;26 using KXMLCore::SharedPtr; 27 27 28 28 namespace KJS { -
trunk/JavaScriptCore/kjs/shared_ptr.h
r10352 r10399 24 24 #define KXMLCORE_SHARED_PTR_H 25 25 26 namespace kxmlcore {26 namespace KXMLCore { 27 27 28 // FIXME: Change template name to RefPtr? 28 29 template <class T> class SharedPtr 29 30 { 30 31 public: 31 SharedPtr() : m_ptr( 0) {}32 explicit SharedPtr(T *ptr) : m_ptr(ptr) { if (m_ptr) m_ptr->ref(); }33 SharedPtr(const SharedPtr &o) : m_ptr(o.m_ptr) { if ( m_ptr) m_ptr->ref(); }34 ~SharedPtr() { if ( m_ptr) m_ptr->deref(); }32 SharedPtr() : m_ptr(NULL) {} 33 SharedPtr(T *ptr) : m_ptr(ptr) { if (ptr) ptr->ref(); } 34 SharedPtr(const SharedPtr &o) : m_ptr(o.m_ptr) { if (T *ptr = m_ptr) ptr->ref(); } 35 ~SharedPtr() { if (T *ptr = m_ptr) ptr->deref(); } 35 36 36 template <class U> explicit SharedPtr(SharedPtr<U> o) : m_ptr(o.get()) { if (m_ptr) m_ptr->ref(); } 37 38 bool isNull() const { return m_ptr == 0; } 39 bool notNull() const { return m_ptr != 0; } 37 template <class U> SharedPtr(const SharedPtr<U> &o) : m_ptr(o.get()) { if (T *ptr = m_ptr) ptr->ref(); } 40 38 41 void reset() { if (m_ptr) m_ptr->deref(); m_ptr = 0; } 42 void reset(T *o) { if (o) o->ref(); if (m_ptr) m_ptr->deref(); m_ptr = o; } 39 // FIXME: Deprecate in favor of operators below, then remove? 40 bool isNull() const { return m_ptr == NULL; } 41 bool notNull() const { return m_ptr != NULL; } 42 43 // FIXME: Deprecate in favor of operator=, then remove? 44 void reset() { if (T *ptr = m_ptr) ptr->deref(); m_ptr = NULL; } 45 void reset(T *o) { if (o) o->ref(); if (T *ptr = m_ptr) ptr->deref(); m_ptr = o; } 43 46 44 T * get() const { return m_ptr; } 47 T *get() const { return m_ptr; } 48 45 49 T &operator*() const { return *m_ptr; } 46 50 T *operator->() const { return m_ptr; } 47 51 48 bool operator!() const { return m_ptr == 0; } 49 operator bool() const { return m_ptr != 0; } 50 51 inline friend bool operator==(const SharedPtr &a, const SharedPtr &b) { return a.m_ptr == b.m_ptr; } 52 inline friend bool operator==(const SharedPtr &a, const T *b) { return a.m_ptr == b; } 53 inline friend bool operator==(const T *a, const SharedPtr &b) { return a == b.m_ptr; } 52 bool operator!() const { return m_ptr == NULL; } 53 operator bool() const { return m_ptr != NULL; } 54 54 55 55 SharedPtr &operator=(const SharedPtr &); … … 57 57 58 58 private: 59 T* m_ptr; 59 T *m_ptr; 60 61 operator int() const; // deliberately not implemented; helps prevent operator bool from converting to int accidentally 60 62 }; 61 63 62 64 template <class T> SharedPtr<T> &SharedPtr<T>::operator=(const SharedPtr<T> &o) 63 65 { 64 if (o.m_ptr) 65 o.m_ptr->ref(); 66 if (m_ptr) 67 m_ptr->deref(); 68 m_ptr = o.m_ptr; 66 T *optr = o.m_ptr; 67 if (optr) 68 optr->ref(); 69 if (T *ptr = m_ptr) 70 ptr->deref(); 71 m_ptr = optr; 69 72 return *this; 70 73 } 71 74 72 template <class T> inline SharedPtr<T> &SharedPtr<T>::operator=(T * ptr)75 template <class T> inline SharedPtr<T> &SharedPtr<T>::operator=(T *optr) 73 76 { 74 if ( ptr)75 ptr->ref();76 if ( m_ptr)77 m_ptr->deref();78 m_ptr = ptr;77 if (optr) 78 optr->ref(); 79 if (T *ptr = m_ptr) 80 ptr->deref(); 81 m_ptr = optr; 79 82 return *this; 80 83 } 81 84 82 template <class T> inline bool operator!=(const SharedPtr<T> &a, const SharedPtr<T> &b) { return !(a==b); } 83 template <class T> inline bool operator!=(const SharedPtr<T> &a, const T *b) { return !(a == b); } 84 template <class T> inline bool operator!=(const T *a, const SharedPtr<T> &b) { return !(a == b); } 85 template <class T> inline bool operator==(const SharedPtr<T> &a, const SharedPtr<T> &b) { return a.get() == b.get(); } 86 template <class T> inline bool operator==(const SharedPtr<T> &a, const T *b) { return a.get() == b; } 87 template <class T> inline bool operator==(const T *a, const SharedPtr<T> &b) { return a == b.get(); } 88 89 template <class T> inline bool operator!=(const SharedPtr<T> &a, const SharedPtr<T> &b) { return a.get() != b.get(); } 90 template <class T> inline bool operator!=(const SharedPtr<T> &a, const T *b) { return a.get() != b; } 91 template <class T> inline bool operator!=(const T *a, const SharedPtr<T> &b) { return a != b.get(); } 85 92 86 93 template <class T, class U> inline SharedPtr<T> static_pointer_cast(const SharedPtr<U> &p) { return SharedPtr<T>(static_cast<T *>(p.get())); }
Note:
See TracChangeset
for help on using the changeset viewer.