Finished implementation of UA layer (to be tested)

git-svn-id: https://svn.pjsip.org/repos/pjproject/trunk@127 74dad513-b988-da41-8d7b-12977e46ad98
diff --git a/pjlib/include/pj++/list.hpp b/pjlib/include/pj++/list.hpp
index 433bd51..456e87d 100644
--- a/pjlib/include/pj++/list.hpp
+++ b/pjlib/include/pj++/list.hpp
@@ -63,7 +63,7 @@
         }
 	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 @@
         }
 	iterator operator++() 
         { 
-            return iterator(node_->next); 
+            return iterator((List_Node*)node_->next); 
         }
 	bool operator==(const iterator &rhs) 
         { 
@@ -121,6 +121,30 @@
     }
 
     //
+    // 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 @@
 	// 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 02b5433..d260414 100644
--- a/pjlib/include/pj++/pool.hpp
+++ b/pjlib/include/pj++/pool.hpp
@@ -123,6 +123,14 @@
     }
 
     //
+    // 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 1c86898..e16132f 100644
--- a/pjlib/include/pj++/string.hpp
+++ b/pjlib/include/pj++/string.hpp
@@ -40,9 +40,9 @@
     }
 
     //
-    // 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,41 +50,52 @@
     //
     // 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 from const pj_str_t& (use with care!).
+    //
+    explicit Pj_String(const pj_str_t &s)
+    {
+	ptr = (char*)s.ptr;
+	slen = s.slen;
     }
 
     //
     // Construct by copying from const pj_str_t*.
     //
-    Pj_String(Pj_Pool *pool, const pj_str_t *s)
+    Pj_String(Pj_Pool &pool, const pj_str_t *s)
     {
 	set(pool, s);
     }
 
     //
-    // Construct from another Pj_String
+    // Construct by copying from Pj_String
     //
-    explicit Pj_String(Pj_String &rhs)
+    Pj_String(Pj_Pool &pool, const Pj_String &rhs)
     {
-	set(rhs);
+	set(pool, rhs);
     }
 
     //
-    // Construct by copying from Pj_String
+    // Construct from another Pj_String, use with care!
     //
-    Pj_String(Pj_Pool *pool, const Pj_String &rhs)
+    explicit Pj_String(const Pj_String &rhs)
     {
-	set(pool, rhs);
+	ptr = rhs.ptr;
+	slen = rhs.slen;
     }
 
     //
@@ -104,6 +115,22 @@
     }
 
     //
+    // 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 @@
     //
     // 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 @@
     //
     // 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 @@
     //
     // 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 @@
     }
 
     ///
-    // 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 e0c2e23..7e165a5 100644
--- a/pjlib/include/pj++/types.hpp
+++ b/pjlib/include/pj++/types.hpp
@@ -156,5 +156,19 @@
 
 };
 
+//
+// 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__ */