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