Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tnl-dev
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
TNL
tnl-dev
Commits
097bcc0b
There was an error fetching the commit references. Please try again later.
Commit
097bcc0b
authored
6 years ago
by
Tomáš Oberhuber
Committed by
Tomáš Oberhuber
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Tunning comments in String.h.
parent
10863b85
No related branches found
No related tags found
1 merge request
!15
Nina
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/TNL/String.h
+127
-133
127 additions, 133 deletions
src/TNL/String.h
with
127 additions
and
133 deletions
src/TNL/String.h
+
127
−
133
View file @
097bcc0b
...
...
@@ -25,141 +25,135 @@ class String;
template
<
typename
T
>
String
convertToString
(
const
T
&
value
);
//! Class for managing strings
/////
// \brief Class for managing strings
class
String
{
//! Pointer to char ended with zero
char
*
string
;
//! Length of the allocated piece of memory
int
length
;
public:
//! Basic constructor
String
();
//! Constructor from const char*
String
(
const
char
*
str
);
//////
/// Constructor with char pointer
///
/// @param prefix_cut_off says length of the prefix that is going to be omitted and
/// @param sufix_cut_off says the same about sufix.
String
(
const
char
*
c
,
int
prefix_cut_off
,
int
sufix_cut_off
=
0
);
//! Copy constructor
String
(
const
String
&
str
);
//////
/// Templated constructor
///
/// It must be explicit otherwise it is called recursively from inside of its
/// definition ( in operator << ). It leads to stack overflow and segmentation fault.
template
<
typename
T
>
explicit
String
(
const
T
&
value
)
:
string
(
nullptr
),
length
(
0
)
{
std
::
stringstream
str
;
str
<<
value
;
setString
(
str
.
str
().
data
()
);
}
String
(
const
bool
b
);
//! Destructor
~
String
();
static
String
getType
();
//! Return length of the string
int
getLength
()
const
;
int
getSize
()
const
;
//! Return currently allocated size
int
getAllocatedSize
()
const
;
//! Reserve space for given number of characters
void
setSize
(
int
size
);
//! Set string from given char pointer
/*! @param prefix_cut_off says length of the prefix that is going to be omitted and
@param sufix_cut_off says the same about sufix.
*/
void
setString
(
const
char
*
c
,
int
prefix_cut_off
=
0
,
int
sufix_cut_off
=
0
);
//! Return pointer to data
const
char
*
getString
()
const
;
//! Return pointer to data
char
*
getString
();
//! Operator for accesing particular chars of the string
const
char
&
operator
[](
int
i
)
const
;
//! Operator for accesing particular chars of the string
char
&
operator
[](
int
i
);
/****
* Operators for C strings
*/
String
&
operator
=
(
const
char
*
str
);
String
&
operator
+=
(
const
char
*
str
);
String
operator
+
(
const
char
*
str
)
const
;
bool
operator
==
(
const
char
*
str
)
const
;
bool
operator
!=
(
const
char
*
str
)
const
;
/****
* Operators for Strings
*/
String
&
operator
=
(
const
String
&
str
);
String
&
operator
+=
(
const
String
&
str
);
String
operator
+
(
const
String
&
str
)
const
;
bool
operator
==
(
const
String
&
str
)
const
;
bool
operator
!=
(
const
String
&
str
)
const
;
/****
* Operators for single characters
*/
String
&
operator
=
(
char
str
);
String
&
operator
+=
(
char
str
);
String
operator
+
(
char
str
)
const
;
bool
operator
==
(
char
str
)
const
;
bool
operator
!=
(
char
str
)
const
;
//! Cast to bool operator
operator
bool
()
const
;
//! Cast to bool with negation operator
bool
operator
!
()
const
;
String
replace
(
const
String
&
pattern
,
const
String
&
replaceWith
,
int
count
=
0
)
const
;
String
strip
(
char
strip
=
' '
)
const
;
//! Split the string into list of strings w.r.t. given separator.
int
split
(
Containers
::
List
<
String
>&
list
,
const
char
separator
=
' '
)
const
;
//! Write to a binary file
bool
save
(
File
&
file
)
const
;
//! Read from binary file
bool
load
(
File
&
file
);
//! Broadcast to other nodes in MPI cluster
// void MPIBcast( int root, MPI_Comm mpi_comm = MPI_COMM_WORLD );
//! Read one line from given stream.
bool
getLine
(
std
::
istream
&
stream
);
friend
std
::
ostream
&
operator
<<
(
std
::
ostream
&
stream
,
const
String
&
str
);
public:
/////
/// \brief Basic constructor
String
();
/////
/// \brief Constructor with char pointer.
/// Constructor with char pointer.
/// @param prefix_cut_off says length of the prefix that is going to be omitted and
/// @param sufix_cut_off says the same about suffix.
String
(
const
char
*
c
,
int
prefix_cut_off
=
0
,
int
sufix_cut_off
=
0
);
static
String
getType
();
//! Copy constructor
String
(
const
String
&
str
);
//! Convert anything to a string
template
<
typename
T
>
explicit
String
(
T
value
)
:
string
(
nullptr
),
length
(
0
)
{
setString
(
convertToString
(
value
).
getString
()
);
}
//! Destructor
~
String
();
//! Return length of the string
int
getLength
()
const
;
int
getSize
()
const
;
//! Return currently allocated size
int
getAllocatedSize
()
const
;
//! Reserve space for given number of characters
void
setSize
(
int
size
);
//! Set string from given char pointer
/*! @param prefix_cut_off says length of the prefix that is going to be omitted and
@param sufix_cut_off says the same about sufix.
*/
void
setString
(
const
char
*
c
,
int
prefix_cut_off
=
0
,
int
sufix_cut_off
=
0
);
//! Return pointer to data
const
char
*
getString
()
const
;
//! Return pointer to data
char
*
getString
();
//! Operator for accesing particular chars of the string
const
char
&
operator
[](
int
i
)
const
;
//! Operator for accesing particular chars of the string
char
&
operator
[](
int
i
);
/****
* Operators for C strings
*/
String
&
operator
=
(
const
char
*
str
);
String
&
operator
+=
(
const
char
*
str
);
String
operator
+
(
const
char
*
str
)
const
;
bool
operator
==
(
const
char
*
str
)
const
;
bool
operator
!=
(
const
char
*
str
)
const
;
/****
* Operators for Strings
*/
String
&
operator
=
(
const
String
&
str
);
String
&
operator
+=
(
const
String
&
str
);
String
operator
+
(
const
String
&
str
)
const
;
bool
operator
==
(
const
String
&
str
)
const
;
bool
operator
!=
(
const
String
&
str
)
const
;
/****
* Operators for single characters
*/
String
&
operator
=
(
char
str
);
String
&
operator
+=
(
char
str
);
String
operator
+
(
char
str
)
const
;
bool
operator
==
(
char
str
)
const
;
bool
operator
!=
(
char
str
)
const
;
//! Cast to bool operator
operator
bool
()
const
;
//! Cast to bool with negation operator
bool
operator
!
()
const
;
String
replace
(
const
String
&
pattern
,
const
String
&
replaceWith
,
int
count
=
0
)
const
;
String
strip
(
char
strip
=
' '
)
const
;
//! Split the string into list of strings w.r.t. given separator.
int
split
(
Containers
::
List
<
String
>&
list
,
const
char
separator
=
' '
)
const
;
//! Write to a binary file
bool
save
(
File
&
file
)
const
;
//! Read from binary file
bool
load
(
File
&
file
);
//! Broadcast to other nodes in MPI cluster
// void MPIBcast( int root, MPI_Comm mpi_comm = MPI_COMM_WORLD );
//! Read one line from given stream.
bool
getLine
(
std
::
istream
&
stream
);
friend
std
::
ostream
&
operator
<<
(
std
::
ostream
&
stream
,
const
String
&
str
);
protected
:
//! Pointer to char ended with zero
char
*
string
;
//! Length of the allocated piece of memory
int
length
;
};
String
operator
+
(
char
string1
,
const
String
&
string2
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment