World Builder  1.1.0-pre
A geodynamic initial conditions generator
feature_utilities.cc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2018-2024 by the authors of the World Builder code.
3 
4  This file is part of the World Builder.
5 
6  This program is free software: you can redistribute it and/or modify
7  it under the terms of the GNU Lesser General Public License as published
8  by the Free Software Foundation, either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public License
17  along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19 
21 
22 
23 namespace WorldBuilder
24 {
25  namespace Features
26  {
27  namespace FeatureUtilities
28  {
30  string_operations_to_enum(const std::string &operation)
31  {
32  if (operation == "add") return Operations::ADD;
33  if (operation == "subtract") return Operations::SUBTRACT;
34  if (operation == "replace defined only") return Operations::REPLACE_DEFINED_ONLY;
35 
36  WBAssert(operation == "replace", "Could not find operation: " << operation << '.');
37  return Operations::REPLACE;
38  }
39 
40  size_t
41  add_vector_unique(std::vector<std::string> &vector,const std::string &add_string)
42  {
43  for (size_t i = 0; i < vector.size(); ++i)
44  {
45  if (vector[i] == add_string)
46  {
47  return i;
48  }
49  }
50 
51  vector.push_back(add_string);
52  return vector.size()-1;
53  }
54  } // namespace FeatureUtilities
55  } // namespace Features
56 } // namespace WorldBuilder
size_t add_vector_unique(std::vector< std::string > &vector, const std::string &add_string)
Operations string_operations_to_enum(const std::string &operation)
#define WBAssert(condition, message)
Definition: assert.h:27