bpp-core3  3.0.0
AbstractParametrizable.cpp
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: The Bio++ Development Group
2 //
3 // SPDX-License-Identifier: CECILL-2.1
4 
6 
7 using namespace bpp;
8 using namespace std;
9 
10 void AbstractParametrizable::setNamespace(const std::string& prefix)
11 {
12  // We need to update all parameter names!
13  // First correct the global parameter list
14  string currentName;
15  for (unsigned int i = 0; i < parameters_.size(); i++)
16  {
17  currentName = parameters_[i].getName();
18  if (TextTools::startsWith(currentName, prefix_))
19  parameters_[i].setName(prefix + currentName.substr(prefix_.size()));
20  else
21  parameters_[i].setName(prefix + currentName);
22  }
23 
24  // Then we store the new namespace:
25  prefix_ = prefix;
26 }
27 
28 std::string AbstractParametrizable::getParameterNameWithoutNamespace(const std::string& name) const
29 {
30  if (TextTools::startsWith(name, prefix_))
31  return name.substr(prefix_.size());
32  else
33  return name;
34 }
void setNamespace(const std::string &prefix) override
Set the namespace for the parameter names.
STL namespace.
std::string getParameterNameWithoutNamespace(const std::string &name) const override
Resolves a parameter name according to the current namespace.
bool startsWith(const std::string &s, const std::string &pattern)
Tell is a string begins with a certain motif.
Definition: TextTools.cpp:402