Re: Common C++

Scott Smedley <[email protected]> Thu, 22 Oct 2009 13:17:50 +1000
Newsgroups gmane.comp.gnu.bayonne.devel
Message-ID <[email protected]>
--3MwIy2ne0vdjdPXF
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Hi David,

> The main svn is at savannah (http://savannah.gnu.org/projects/commoncpp)

Thanks.

> I would be happy to take in a patch for this as I was looking to do a new
> release very soon.

Please find attached. (Generated with 'svn diff', I hope that's right.)

Note:

1. unless I am missing something, code in IPV4Cidr::set() &
   IPV6Cidr::set() is redundant - it doesn't DO anything. It was easier
   to remove the offending code than to fix the const-correctness.
2. Trivial modification to demo/SampleSocketPort.cpp is so I can do:
   make SampleSocketPort.o CPPFLAGS=-DNO_EXAMPLE
   and link against the resultant object code with my own program.
   (Previously I had to hand-edit & remove '#define WITH_EXAMPLE'.)

Scott. :)

--3MwIy2ne0vdjdPXF
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="commoncpp.gcc4.4.diff"

Index: demo/SampleSocketPort.cpp
===================================================================
--- demo/SampleSocketPort.cpp	(revision 937)
+++ demo/SampleSocketPort.cpp	(working copy)
@@ -242,11 +242,9 @@
 
 
 
-#define WITH_EXAMPLE
+#ifndef NO_EXAMPLE
 
-#ifdef WITH_EXAMPLE
 
-
 /************ THE FOLLOWING CODE DEMONSTRATES THE USE OF THE ABOVE CLASS ********************
  ****
  ****	To test it, compile with:
Index: src/string.cpp
===================================================================
--- src/string.cpp	(revision 937)
+++ src/string.cpp	(working copy)
@@ -719,7 +719,7 @@
 	return def;
 }
 
-const size_t String::getSize(void) const
+size_t String::getSize(void) const
 {
 	if(isBig())
 		return content.bigstring.size;
@@ -749,7 +749,7 @@
 	return chars;
 }
 
-const size_t String::getLength(void) const
+size_t String::getLength(void) const
 {
 	if(isBig())
 		return content.bigstring.length;
Index: src/cidr.cpp
===================================================================
--- src/cidr.cpp	(revision 937)
+++ src/cidr.cpp	(working copy)
@@ -189,7 +189,6 @@
 void IPV4Cidr::set(const char *cp)
 {
 	char cbuf[INET_IPV4_ADDRESS_SIZE];
-	char *ep;
 	unsigned dots = 0;
 #ifdef	WIN32
 	DWORD addr;
@@ -198,16 +197,7 @@
 	memset(&netmask, 0, sizeof(netmask));
 	bitset((bit_t *)&netmask, getMask(cp));
 	setString(cbuf, sizeof(cbuf), cp);
-	
-#if defined(_MSC_VER) && _MSC_VER >= 1500
-	ep = (char *)strchr(cp, '/');
-#else
- 	ep = strchr(cp, '/');
-#endif
 
-	if(ep)
-		*ep = 0;
-
 	cp = cbuf;
 	while(NULL != (cp = strchr(cp, '.'))) {
 		++dots;
@@ -327,15 +317,10 @@
 void IPV6Cidr::set(const char *cp)
 {
 	char cbuf[INET_IPV6_ADDRESS_SIZE];
-	char *ep;
 
 	memset(&netmask, 0, sizeof(netmask));
 	bitset((bit_t *)&netmask, getMask(cp));
 	setString(cbuf, sizeof(cbuf), cp);
-	ep = strchr(cp, '/');
-	if(ep)
-		*ep = 0;
-
 	inet_pton(AF_INET6, cbuf, &network);
 	bitmask((bit_t *)&network, (bit_t *)&netmask, sizeof(network));
 }
Index: inc/cc++/string.h
===================================================================
--- inc/cc++/string.h	(revision 937)
+++ inc/cc++/string.h	(working copy)
@@ -319,14 +319,14 @@
 	 *
 	 * @return string length.
 	 */
-	const size_t getLength(void) const;
+	size_t getLength(void) const;
 
 	/**
 	 * Get the allocation size of the string variable.
 	 *
 	 * @return allocation size.
 	 */
-	const size_t getSize(void) const;
+	size_t getSize(void) const;
 
 	/**
 	 * Return true if string is empty.
@@ -675,7 +675,7 @@
 	 *
 	 * @return character code.
 	 */
-	inline const char operator[](unsigned ind) const
+	inline char operator[](unsigned ind) const
 		{return at(ind);};
 
 	/**

--3MwIy2ne0vdjdPXF
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Bayonne-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/bayonne-devel

--3MwIy2ne0vdjdPXF--