OpenMD
3.2
Molecular Dynamics in the Open
Toggle main menu visibility
Loading...
Searching...
No Matches
StringUtils.hpp
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2004-present, The University of Notre Dame. All rights
3
* reserved.
4
*
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions are met:
7
*
8
* 1. Redistributions of source code must retain the above copyright notice,
9
* this list of conditions and the following disclaimer.
10
*
11
* 2. Redistributions in binary form must reproduce the above copyright notice,
12
* this list of conditions and the following disclaimer in the documentation
13
* and/or other materials provided with the distribution.
14
*
15
* 3. Neither the name of the copyright holder nor the names of its
16
* contributors may be used to endorse or promote products derived from
17
* this software without specific prior written permission.
18
*
19
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
* POSSIBILITY OF SUCH DAMAGE.
30
*
31
* SUPPORT OPEN SCIENCE! If you use OpenMD or its source code in your
32
* research, please cite the following paper when you publish your work:
33
*
34
* [1] Drisko et al., J. Open Source Softw. 9, 7004 (2024).
35
*
36
* Good starting points for code and simulation methodology are:
37
*
38
* [2] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005).
39
* [3] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006).
40
* [4] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008).
41
* [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011).
42
* [6] Kuang & Gezelter, Mol. Phys., 110, 691-701 (2012).
43
* [7] Lamichhane, Gezelter & Newman, J. Chem. Phys. 141, 134109 (2014).
44
* [8] Bhattarai, Newman & Gezelter, Phys. Rev. B 99, 094106 (2019).
45
* [9] Drisko & Gezelter, J. Chem. Theory Comput. 20, 4986-4997 (2024).
46
*/
47
48
/**
49
* @file StringUtils.hpp
50
* @author Dan Gezelter
51
* @date 10/18/2004
52
* @version 1.0
53
*/
54
55
#ifndef UTILS_STRINGUTILS_HPP
56
#define UTILS_STRINGUTILS_HPP
57
58
#include <cstring>
59
#include <fstream>
60
#include <iostream>
61
#include <sstream>
62
#include <string>
63
64
namespace
OpenMD
{
65
66
/**
67
* Strip comments from a string
68
* @param S
69
*/
70
std::string
stripComments
(
const
std::string& S);
71
72
/**
73
* Converts a string to UPPER CASE
74
* @param S
75
*/
76
std::string
UpperCase
(
const
std::string& S);
77
78
/**
79
* Finds the location of the string "begin <startText>" in an input stream.
80
* @param theStream
81
* @param startText
82
*
83
* @return the line number of the block within the theStream
84
*/
85
int
findBegin
(std::istream& theStream,
const
char
* startText);
86
87
/**
88
* discovers whether or not the line contains the "end" token
89
*
90
* @param line The line to test
91
*
92
* @return int (==1 if the line has "end", ==0 if not).
93
*/
94
int
isEndLine
(
char
* line);
95
96
bool
CaseInsensitiveEquals(
char
ch1,
char
ch2);
97
98
size_t
CaseInsensitiveFind(
const
std::string& str1,
const
std::string& str2);
99
100
/**
101
* Convert a variable to a string
102
* @tparam T data type
103
* @param v data to be converted
104
* @return a string
105
*/
106
template
<
typename
T>
107
std::string
toString
(
const
T& v) {
108
std::ostringstream oss;
109
if
(!(oss << v)) { std::cerr <<
"toString Error"
<< std::endl; }
110
return
oss.str();
111
}
112
113
template
<
typename
T>
114
T lexi_cast(
const
std::string& str) {
115
T result;
116
std::istringstream iss(str);
117
if
(!(iss >> result)) { std::cerr <<
"lexi_cast Error"
<< std::endl; }
118
return
result;
119
}
120
121
template
<
typename
T>
122
bool
isType(
const
std::string& str) {
123
T result;
124
std::istringstream iss(str);
125
bool
ret =
true
;
126
if
(!(iss >> result)) { ret =
false
; }
127
return
ret;
128
}
129
130
bool
isInteger(
const
std::string& str);
131
132
std::string OpenMD_itoa(
int
value,
unsigned
int
base = 10);
133
134
/**@todo need implementation */
135
std::string
getPrefix
(
const
std::string& str);
136
137
template
<
class
ContainerType>
138
std::string containerToString(
const
ContainerType& cont) {
139
std::ostringstream oss;
140
oss <<
"("
;
141
typename
ContainerType::const_iterator i = cont.begin();
142
if
(i != cont.end()) {
143
oss << *i;
144
++i;
145
}
146
for
(; i != cont.end(); ++i) {
147
oss <<
", "
;
148
oss << *i;
149
}
150
oss <<
")"
;
151
return
oss.str();
152
}
153
}
// namespace OpenMD
154
155
#endif
OpenMD
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.
Definition
ActionCorrFunc.cpp:63
OpenMD::UpperCase
std::string UpperCase(const std::string &S)
Converts a string to UPPER CASE.
Definition
StringUtils.cpp:99
OpenMD::findBegin
int findBegin(std::istream &theStream, const char *startText)
Finds the location of the string "begin <startText>" in an input stream.
Definition
StringUtils.cpp:109
OpenMD::getPrefix
std::string getPrefix(const std::string &str)
Definition
StringUtils.cpp:207
OpenMD::toString
std::string toString(const T &v)
Convert a variable to a string.
Definition
StringUtils.hpp:107
OpenMD::isEndLine
int isEndLine(char *line)
discovers whether or not the line contains the "end" token
Definition
StringUtils.cpp:160
OpenMD::stripComments
std::string stripComments(const std::string &S)
Strip comments from a string.
Definition
StringUtils.cpp:64
utils
StringUtils.hpp
Generated on
for OpenMD by
1.17.0