| 
									
										
										
										
											2010-10-14 12:54:38 +08:00
										 |  |  | /* ----------------------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  * GTSAM Copyright 2010, Georgia Tech Research Corporation,  | 
					
						
							|  |  |  |  * Atlanta, Georgia 30332-0415 | 
					
						
							|  |  |  |  * All Rights Reserved | 
					
						
							|  |  |  |  * Authors: Frank Dellaert, et al. (see THANKS for the full author list) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  * See LICENSE for the license information | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  * -------------------------------------------------------------------------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "SimpleString.h"
 | 
					
						
							|  |  |  | #include <string.h>
 | 
					
						
							|  |  |  | #include <stdio.h>
 | 
					
						
							|  |  |  | #include <stdlib.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static const int DEFAULT_SIZE = 20; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | SimpleString::SimpleString () | 
					
						
							| 
									
										
										
										
											2010-07-17 03:30:38 +08:00
										 |  |  | : buffer_(new char [1]) | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-07-17 03:30:38 +08:00
										 |  |  | 	buffer_ [0] = '\0'; | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | SimpleString::SimpleString (const char *otherBuffer) | 
					
						
							| 
									
										
										
										
											2010-07-17 03:30:38 +08:00
										 |  |  | : buffer_ (new char [strlen (otherBuffer) + 1]) | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-07-17 03:30:38 +08:00
										 |  |  | 	strcpy (buffer_, otherBuffer); | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | SimpleString::SimpleString (const SimpleString& other) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2010-07-17 03:30:38 +08:00
										 |  |  | 	buffer_ = new char [other.size() + 1]; | 
					
						
							|  |  |  | 	strcpy(buffer_, other.buffer_); | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | SimpleString SimpleString::operator= (const SimpleString& other) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-05-24 10:55:41 +08:00
										 |  |  | 	delete [] buffer_; | 
					
						
							| 
									
										
										
										
											2010-07-17 03:30:38 +08:00
										 |  |  | 	buffer_ = new char [other.size() + 1]; | 
					
						
							|  |  |  | 	strcpy(buffer_, other.buffer_); | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 	return *this; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-17 03:30:38 +08:00
										 |  |  | SimpleString SimpleString::operator+ (const SimpleString& other) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	SimpleString ret; | 
					
						
							| 
									
										
										
										
											2012-05-24 10:55:41 +08:00
										 |  |  | 	delete [] ret.buffer_; | 
					
						
							| 
									
										
										
										
											2010-07-17 03:30:38 +08:00
										 |  |  | 	ret.buffer_ = new char [size() + other.size() - 1]; | 
					
						
							|  |  |  | 	strcpy(ret.buffer_, buffer_); | 
					
						
							|  |  |  | 	strcat(ret.buffer_, other.buffer_); | 
					
						
							|  |  |  | 	return ret; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | char *SimpleString::asCharString () const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2010-07-17 03:30:38 +08:00
										 |  |  | 	return buffer_; | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int SimpleString::size() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2010-07-17 03:30:38 +08:00
										 |  |  | 	return strlen (buffer_); | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | SimpleString::~SimpleString () | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2010-07-17 03:30:38 +08:00
										 |  |  | 	delete [] buffer_; | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool operator== (const SimpleString& left, const SimpleString& right) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return !strcmp (left.asCharString (), right.asCharString ()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | SimpleString StringFrom (bool value) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	char buffer [sizeof ("false") + 1]; | 
					
						
							|  |  |  | 	sprintf (buffer, "%s", value ? "true" : "false"); | 
					
						
							|  |  |  | 	return SimpleString(buffer); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | SimpleString StringFrom (const char *value) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return SimpleString(value); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | SimpleString StringFrom (long value) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	char buffer [DEFAULT_SIZE]; | 
					
						
							|  |  |  | 	sprintf (buffer, "%ld", value); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return SimpleString(buffer); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | SimpleString StringFrom (double value) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	char buffer [DEFAULT_SIZE]; | 
					
						
							| 
									
										
										
										
											2012-04-09 11:02:30 +08:00
										 |  |  | 	sprintf (buffer, "%lg", value); | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return SimpleString(buffer); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | SimpleString StringFrom (const SimpleString& value) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return SimpleString(value); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 |