Garfield++
v2r0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
String.h
Go to the documentation of this file.
1
#ifndef STRING_SWITCHING_H
2
#define STRING_SWITCHING_H
3
4
/*
5
This is the file for indication which String class should be used by
6
the wcpplib library. This library does not depend on very sophisticated
7
operations with strings. The strings are used for inclusion of notations
8
or character names in various objects and also for keeping the file names.
9
The typical string operations used in wcpplib are
10
initialization from characters array,
11
convertion to characters array,
12
initialization from integer number,
13
and addition of strings.
14
Such simple operations are either supported by any library or some of them
15
can be easily added, as done below with STL.
16
Since the wcpplib was started before the standard library was firmly
17
established, and because there were many other libraries and it was not
18
clear which of them will predominate,
19
the source texts of wcpplib reference the string type by
20
symbolic name "String" (which seem to be unexisting in all known libraries
21
except GNU library),
22
and this type can and must be redefined right here, in this file,
23
to actual name of string class of actually applied library (except GNU library,
24
for which it should not be redefined at all).
25
26
There are currently 3 options.
27
One is String class from gnu C++ library.
28
(This library seems to be not supported anymore).
29
Another is HepString from CLHEP library.
30
(This collaboration have decided to eliminate strings in favour to std.)
31
The last is standard library string.
32
The standard library appears to be the most inconvenient (!) in supporting
33
the strings. It does not support conversion from integers and long integers
34
to strings, and it does not support the default conversion of strings to
35
char*. Therefore when the support of other strings dissappeared,
36
I had to edit the programs to pass to this "standard".
37
The first type of conversions is performed by little function long_to_String()
38
defined as inline below. The second type of conversions is performed
39
in program with the use of macro USE_STLSTRING and c_str() member function
40
like this:
41
42
Example of program:
43
#ifdef USE_STLSTRING
44
ifstream fh(hfile.c_str()); // use standard library
45
#else
46
ifstream fh(hfile); // most of other libraries
47
#endif
48
49
Not convenient! Hope there was real reasons to forbid default conversions in
50
standard library.
51
52
53
Copyright (c) 2001 I. B. Smirnov
54
55
Permission to use, copy, modify, distribute and sell this file
56
and its documentation for any purpose is hereby granted without fee,
57
provided that the above copyright notice, this permission notice,
58
and notices about any modifications of the original text
59
appear in all copies and in supporting documentation.
60
It is provided "as is" without express or implied warranty.
61
*/
62
63
#include <string>
64
#include <iostream>
65
#include <sstream>
66
67
namespace
Heed
{
68
69
typedef
std::string
String
;
70
71
inline
String
long_to_String
(
const
long
n) {
72
std::ostringstream s;
73
s << n;
74
return
String
(s.str());
75
}
76
77
inline
String
double_to_String
(
const
double
d) {
78
std::ostringstream s;
79
s << d;
80
return
String
(s.str());
81
}
82
83
// puts one \n at the end of string stream:
84
85
inline
void
put_one_n
(std::ostringstream& ost) {
86
long
qost = ost.str().length();
87
if
(qost > 0) {
88
if
(ost.str()[qost - 1] ==
'\n'
) {
// nothing
89
}
else
{
90
ost <<
'\n'
;
91
}
92
}
else
93
ost <<
'\n'
;
94
}
95
96
}
97
98
#endif
Heed
Definition:
BGMesh.cpp:5
Heed::put_one_n
void put_one_n(std::ostringstream &ost)
Definition:
String.h:85
Heed::double_to_String
String double_to_String(const double d)
Definition:
String.h:77
Heed::String
std::string String
Definition:
String.h:69
Heed::long_to_String
String long_to_String(const long n)
Definition:
String.h:71
garfieldpp-v2r0
Heed
wcpplib
util
String.h
Generated by
1.9.6