CppField.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5  *
6  * ArmarX is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * ArmarX is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * @package
19  * @author
20  * @date
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 #include "CppField.h"
25 
27 #include <SimoxUtility/algorithm/string/string_tools.h>
28 
29 namespace armarx
30 {
31 
32  CppField::CppField(const std::string& type, const std::string& name, const std::string& default_value, const std::string& doc):
33  type(type),
34  name(name),
35  default_value(default_value),
36  doc(doc)
37  {
38  if (type.empty())
39  {
40  throw armarx::LocalException("Type of a CppField must not be empty!");
41  }
42  }
43 
44  std::string CppField::getName() const
45  {
46  return name;
47  }
48 
49  std::string CppField::getType() const
50  {
51  return type;
52  }
53 
54  void CppField::setDoc(const std::string& documentation)
55  {
56  doc = documentation;
57  }
58 
59  void CppField::writeCpp(const CppWriterPtr& writer)
60  {
61  if (doc != "")
62  {
63  auto lines = simox::alg::split(doc, "\n", true, false);
64  for (const auto& line : lines)
65  {
66  writer->body.line("/// " + line);
67  }
68  }
69  std::string decl = (type + (name != "" ? " " + name + (default_value != "" ? " = " + default_value : "") : ""));
70 
71  // repair ; at the end
72  if (not simox::alg::ends_with(simox::alg::trim_copy(decl), ";"))
73  {
74  decl += ";";
75  }
76 
77  writer->body.line(decl);
78  }
79 }
LocalException.h
armarx::CppField::setDoc
void setDoc(const std::string &documentation)
Definition: CppField.cpp:54
armarx::CppField::CppField
CppField(const std::string &type, const std::string &name, const std::string &default_value="", const std::string &doc="")
Definition: CppField.cpp:32
armarx::CppField::getType
std::string getType() const
Definition: CppField.cpp:49
armarx::CppField::getName
std::string getName() const
Definition: CppField.cpp:44
CppField.h
armarx::ends_with
bool ends_with(const std::string &haystack, const std::string &needle)
Definition: StringHelpers.cpp:50
armarx::CppWriterPtr
std::shared_ptr< CppWriter > CppWriterPtr
Definition: CppWriter.h:35
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::CppField::writeCpp
void writeCpp(const CppWriterPtr &writer)
Definition: CppField.cpp:59
armarx::split
std::vector< std::string > split(const std::string &source, const std::string &splitBy, bool trimElements=false, bool removeEmptyElements=false)
Definition: StringHelpers.cpp:36