diff options
author | Benny Prijono <bennylp@teluu.com> | 2006-01-30 18:40:05 +0000 |
---|---|---|
committer | Benny Prijono <bennylp@teluu.com> | 2006-01-30 18:40:05 +0000 |
commit | 0d61adeb5f784b45f76d76dad9974f4111fb3c8c (patch) | |
tree | 4fe8830715bd6af57dd91ebca780318a645435cd /pjlib/include/pj++ | |
parent | 7638eeee106fe58a1225f642e733629f29418818 (diff) |
Finished implementation of UA layer (to be tested)
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@127 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjlib/include/pj++')
-rw-r--r-- | pjlib/include/pj++/list.hpp | 30 | ||||
-rw-r--r-- | pjlib/include/pj++/pool.hpp | 8 | ||||
-rw-r--r-- | pjlib/include/pj++/string.hpp | 76 | ||||
-rw-r--r-- | pjlib/include/pj++/types.hpp | 14 |
4 files changed, 101 insertions, 27 deletions
diff --git a/pjlib/include/pj++/list.hpp b/pjlib/include/pj++/list.hpp index 433bd512..456e87d2 100644 --- a/pjlib/include/pj++/list.hpp +++ b/pjlib/include/pj++/list.hpp @@ -63,7 +63,7 @@ public: } const_iterator operator++() { - return const_iterator(node_->next); + return const_iterator((const List_Node *)node_->next); } bool operator==(const const_iterator &rhs) { @@ -99,7 +99,7 @@ public: } iterator operator++() { - return iterator(node_->next); + return iterator((List_Node*)node_->next); } bool operator==(const iterator &rhs) { @@ -121,6 +121,30 @@ public: } // + // You can cast Pj_List to pj_list + // + operator pj_list&() + { + return (pj_list&)root_; + } + operator const pj_list&() + { + return (const pj_list&)root_; + } + + // + // You can cast Pj_List to pj_list* too + // + operator pj_list*() + { + return (pj_list*)&root_; + } + operator const pj_list*() + { + return (const pj_list*)&root_; + } + + // // Check if list is empty. // bool empty() const @@ -318,7 +342,7 @@ private: // If you see error in this line, // it's because List_Node is not derived from Pj_List_Node. List_Node *n = (List_Node*)0; - n = n->next; n = n->prev; + n = (List_Node *)n->next; n = (List_Node *)n->prev; } }; diff --git a/pjlib/include/pj++/pool.hpp b/pjlib/include/pj++/pool.hpp index 02b54336..d2604142 100644 --- a/pjlib/include/pj++/pool.hpp +++ b/pjlib/include/pj++/pool.hpp @@ -123,6 +123,14 @@ public: } // + // You can cast Pj_Pool to pj_pool_t* + // + operator pj_pool_t*() + { + return p_; + } + + // // Get pjlib compatible pool object. // pj_pool_t *pool_() diff --git a/pjlib/include/pj++/string.hpp b/pjlib/include/pj++/string.hpp index 1c868986..e16132f5 100644 --- a/pjlib/include/pj++/string.hpp +++ b/pjlib/include/pj++/string.hpp @@ -40,9 +40,9 @@ public: } // - // Construct the buffer from a char*. + // Construct the buffer from a char* (use with care) // - explicit Pj_String(char *str) + Pj_String(char *str) { set(str); } @@ -50,44 +50,55 @@ public: // // Construct from a const char*. // - Pj_String(Pj_Pool *pool, const char *src) + Pj_String(Pj_Pool &pool, const char *src) { set(pool, src); } // - // Construct from pj_str_t*. + // Construct from pj_str_t&. // - explicit Pj_String(pj_str_t *s) + explicit Pj_String(pj_str_t &s) { - set(s); + ptr = s.ptr; + slen = s.slen; } // - // Construct by copying from const pj_str_t*. + // Construct from const pj_str_t& (use with care!). // - Pj_String(Pj_Pool *pool, const pj_str_t *s) + explicit Pj_String(const pj_str_t &s) { - set(pool, s); + ptr = (char*)s.ptr; + slen = s.slen; } // - // Construct from another Pj_String + // Construct by copying from const pj_str_t*. // - explicit Pj_String(Pj_String &rhs) + Pj_String(Pj_Pool &pool, const pj_str_t *s) { - set(rhs); + set(pool, s); } // // Construct by copying from Pj_String // - Pj_String(Pj_Pool *pool, const Pj_String &rhs) + Pj_String(Pj_Pool &pool, const Pj_String &rhs) { set(pool, rhs); } // + // Construct from another Pj_String, use with care! + // + explicit Pj_String(const Pj_String &rhs) + { + ptr = rhs.ptr; + slen = rhs.slen; + } + + // // Construct from a char* and a length. // Pj_String(char *str, pj_size_t len) @@ -104,6 +115,22 @@ public: } // + // You can cast Pj_String to pj_str_t* + // + operator pj_str_t*() + { + return this; + } + + // + // You can cast const Pj_String to const pj_str_t* + // + operator const pj_str_t*() const + { + return this; + } + + // // Get the length of the string. // pj_size_t length() const @@ -138,9 +165,9 @@ public: // // Initialize by copying from a const char*. // - void set(Pj_Pool *pool, const char *s) + void set(Pj_Pool &pool, const char *s) { - pj_strdup2(pool->pool_(), this, s); + pj_strdup2(pool, this, s); } // @@ -154,9 +181,9 @@ public: // // Initialize by copying from const pj_str_t*. // - void set(Pj_Pool *pool, const pj_str_t *s) + void set(Pj_Pool &pool, const pj_str_t *s) { - pj_strdup(pool->pool_(), this, s); + pj_strdup(pool, this, s); } // @@ -186,17 +213,17 @@ public: // // Initialize by copying from a Pj_String*. // - void set(Pj_Pool *pool, const Pj_String *s) + void set(Pj_Pool &pool, const Pj_String *s) { - pj_strdup(pool->pool_(), this, s); + pj_strdup(pool, this, s); } // // Initialize by copying from other Pj_String. // - void set(Pj_Pool *pool, const Pj_String &s) + void set(Pj_Pool &pool, const Pj_String &s) { - pj_strdup(pool->pool_(), this, &s); + pj_strdup(pool, this, &s); } // @@ -353,11 +380,12 @@ public: } /// - // Assign from another Pj_String + // Assign from another Pj_String, use with care! // - Pj_String& operator=(Pj_String &rhs) + Pj_String& operator=(const Pj_String &rhs) { - set(rhs); + ptr = rhs.ptr; + slen = rhs.slen; return *this; } diff --git a/pjlib/include/pj++/types.hpp b/pjlib/include/pj++/types.hpp index e0c2e230..7e165a53 100644 --- a/pjlib/include/pj++/types.hpp +++ b/pjlib/include/pj++/types.hpp @@ -156,5 +156,19 @@ private: }; +// +// Macro to declare common object comparison operators. +// +#define PJ_DECLARE_OPERATORS(rhs_type) \ + bool operator!=(rhs_type rhs) const { \ + return !operator==(rhs); } \ + bool operator<=(rhs_type rhs) const { \ + return operator<(rhs) || operator==(rhs); } \ + bool operator>(rhs_type rhs) const { \ + return !operator<=(rhs); } \ + bool operator>=(rhs_type rhs) const { \ + return !operator<(rhs); } + + #endif /* __PJPP_TYPES_HPP__ */ |