diff --git a/src/Examples/CMakeLists.txt b/src/Examples/CMakeLists.txt index 8fcc4a5de7f5ae768fb9709bddd6d875fd53c257..30502058716dcbff0831e10012fd19c87597e449 100644 --- a/src/Examples/CMakeLists.txt +++ b/src/Examples/CMakeLists.txt @@ -17,3 +17,7 @@ add_subdirectory( flow-vl ) #add_subdirectory( hamilton-jacobi-parallel-map ) #add_subdirectory( fast-sweeping-map ) #add_subdirectory( narrow-band ) + + +ADD_EXECUTABLE( StringExample StringExample.cpp ) +target_link_libraries( StringExample tnl ) \ No newline at end of file diff --git a/src/Examples/StringExample.cpp b/src/Examples/StringExample.cpp index f33da1392cf475cb1b03142057e993e949e9db6c..d6c45dee82f8df3e9fc0074719fce0961b9f8a55 100644 --- a/src/Examples/StringExample.cpp +++ b/src/Examples/StringExample.cpp @@ -1,8 +1,10 @@ #include <iostream> +#include <TNL/String.h> -using namespace TNL +using namespace TNL; +using namespace std; -int main() +int main( int argc, char* argv[] ) { // constructors String str1; @@ -16,23 +18,24 @@ int main() cout << "str4:" << str4 << endl; // functions - int size = str3.getSize(); + /*int size = str3.getSize(); cout << "size of string:" << size << "bytes" << endl; int alloc_size = str3.getAllocatedSize(); cout << "alloc_size:" << alloc_size << endl; - int memory = str1.setSize( 256 ); - cout << "memory:" << memory << endl; + str1.setSize( 256 ); + size = str3.getSize(); + cout << "size of string:" << size << "bytes" << endl;*/ String str setter = str.setString( "Something new" ); cout << "setter:" << setter << endl; - int getter = str4.getString(); + const char* getter = str4.getString(); cout << "getter:" << getter << endl; - String word( computer ) ; + String word( "computer" ) ; third_letter = word[2]; cout << "third_letter:" << third_letter << endl; diff --git a/src/TNL/String.h b/src/TNL/String.h index b981c9df49ee749eef196394cc54ced3c22e1606..37d3878f2f3d19ff76bf12f8e80d4d7dd09fb057 100644 --- a/src/TNL/String.h +++ b/src/TNL/String.h @@ -45,7 +45,6 @@ class String ///// /// \brief Constructor with char pointer. /// - /// Copies the null-terminated character sequence (C-string) pointed by \e c. /// Constructs a string initialized with the 8-bit string \e c, excluding /// the given number of \e prefix_cut_off and \e sufix_cut_off characters. /// @@ -74,6 +73,7 @@ class String /// \brief Converts anything to a string. /// /// This function converts any type of value into type string. + /// @tparam T is a type of a value to be converted /// @param value Word of any type (e.g. int, bool, double,...). template< typename T > String( T value ) @@ -85,7 +85,7 @@ class String /// \brief Destructor. ~String(); - /// Returns the number of characters in given string. Equivalent to getSize(). + /// \brief Returns the number of characters in given string. Equivalent to getSize(). int getLength() const; /// \brief Returns the number of characters in given string. @@ -131,25 +131,23 @@ class String ///// /// \brief Returns pointer to data. /// - /// It returns the content of the given string. The content can not be - /// changed by user. + /// It returns the content of the given string as a constant pointer to char. const char* getString() const; /// \brief Returns pointer to data. /// - /// It returns the content of the given string. The content can be changed - /// by user. + /// It returns the content of the given string as a non-constant pointer to char. char* getString(); ///// - /// \brief Operator for accesing particular chars of the string. + /// \brief Operator for accessing particular chars of the string. /// /// This function overloads operator[](). It returns a reference to /// the character at position \e i in given string. /// The character can not be changed be user. const char& operator[]( int i ) const; - /// \brief Operator for accesing particular chars of the string. + /// \brief Operator for accessing particular chars of the string. /// /// It returns the character at the position \e i in given string as /// a modifiable reference. @@ -260,23 +258,17 @@ class String ///// /// \brief Function for saving file. /// - /// Writes to a binary file and returns boolean expression based on the + /// Writes the string to a binary file and returns boolean expression based on the /// success in writing into the file. bool save( File& file ) const; ///// /// \brief Function for loading from file. /// - /// Reads from binary file and returns boolean expression based on the + /// Reads a string from binary file and returns boolean expression based on the /// success in reading the file. bool load( File& file ); - - // !!! Mozem dat prec??? - // Broadcast to other nodes in MPI cluster - // void MPIBcast( int root, MPI_Comm mpi_comm = MPI_COMM_WORLD ); - - ///// /// \brief Function for getting a line from stream. /// @@ -284,11 +276,11 @@ class String /// expression based on the success in reading the line. bool getLine( std::istream& stream ); - ///toto neviem co friend std::ostream& operator<<( std::ostream& stream, const String& str ); protected: - /// Pointer to char ended with zero ...Preco? + + /// Pointer to char ended with zero byte char* string; /// Length of allocated piece of memory. @@ -302,7 +294,7 @@ String operator+( char string1, const String& string2 ); /// Returns concatenation of \e string1 and \e string2. String operator+( const char* string1, const String& string2 ); -/// Toto neviem co +/// Performs the string output to a stream std::ostream& operator<<( std::ostream& stream, const String& str ); template< typename T >