NOMAD Source  Version 4.0.0 Beta
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
BBInputType.cpp
Go to the documentation of this file.
1 /**
2  \file BBInputType.cpp
3  \brief types for BBInput (implementation)
4  \author Viviane Rochon Montplaisir
5  \date December 2018
6  \see BBInputType.hpp
7  */
8 
9 #include "../Type/BBInputType.hpp"
10 #include "../Util/ArrayOfString.hpp"
11 #include "../Util/Exception.hpp"
12 
13 // Convert a string ("R", "I", "B") to a NOMAD::BBInputType.
15 {
16  NOMAD::BBInputType ret = NOMAD::BBInputType::CONTINUOUS;
17 
18  if (s == "R")
19  {
20  ret = NOMAD::BBInputType::CONTINUOUS;
21  }
22  else if (s == "I")
23  {
24  ret = NOMAD::BBInputType::INTEGER;
25  }
26  else if (s == "B")
27  {
28  ret = NOMAD::BBInputType::BINARY;
29  }
30  else
31  {
32  throw NOMAD::Exception(__FILE__, __LINE__, "Unrecognized string for NOMAD::BBInputType: " + s);
33  }
34 
35  return ret;
36 }
37 
38 
39 // Convert a string containing multiple BBInputTypes (ex "( R I B R )")
40 // to a NOMAD::BBInputTypeList.
41 // Supporting both classic version with parenthesis and modern version without parenthesis.
43 {
44  NOMAD::BBInputTypeList bbInputType;
45  NOMAD::ArrayOfString aos(s);
46  std::size_t arraysize = aos.size();
47  if (arraysize >= 2 && aos[0] == "(" && aos[arraysize-1] == ")")
48  {
49  aos.erase(arraysize-1);
50  aos.erase(0);
51  arraysize -= 2;
52  }
53  for (size_t i = 0; i < arraysize; i++)
54  {
55  bbInputType.push_back(NOMAD::stringToBBInputType(aos[i]));
56  }
57  return bbInputType;
58 }
59 
std::vector< BBInputType > BBInputTypeList
Definition: BBInputType.hpp:32
BBInputType stringToBBInputType(const std::string &s)
Utility for BBInputTypes.
Definition: BBInputType.cpp:14
BBInputTypeList stringToBBInputTypeList(const std::string &s)
Utility for BBInputTypes.
Definition: BBInputType.cpp:42
BBInputType
Enum for blackbox input type.
Definition: BBInputType.hpp:23