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
26#include <SimoxUtility/algorithm/string/string_tools.h>
27
29
30namespace armarx
31{
32
33 CppField::CppField(const std::string& type,
34 const std::string& name,
35 const std::string& default_value,
36 const std::string& doc) :
37 type(type), name(name), default_value(default_value), doc(doc)
38 {
39 if (type.empty())
40 {
41 throw armarx::LocalException("Type of a CppField must not be empty!");
42 }
43 }
44
45 std::string
47 {
48 return name;
49 }
50
51 std::string
53 {
54 return type;
55 }
56
57 void
58 CppField::setDoc(const std::string& documentation)
59 {
60 doc = documentation;
61 }
62
63 void
65 {
66 if (doc != "")
67 {
68 auto lines = simox::alg::split(doc, "\n", true, false);
69 for (const auto& line : lines)
70 {
71 writer->body.line("/// " + line);
72 }
73 }
74 std::string decl =
75 (type +
76 (name != "" ? " " + name + (default_value != "" ? " = " + default_value : "") : ""));
77
78 // repair ; at the end
79 if (not simox::alg::ends_with(simox::alg::trim_copy(decl), ";"))
80 {
81 decl += ";";
82 }
83
84 writer->body.line(decl);
85 }
86} // namespace armarx
void setDoc(const std::string &documentation)
Definition CppField.cpp:58
void writeCpp(const CppWriterPtr &writer)
Definition CppField.cpp:64
std::string getType() const
Definition CppField.cpp:52
std::string getName() const
Definition CppField.cpp:46
CppField(const std::string &type, const std::string &name, const std::string &default_value="", const std::string &doc="")
Definition CppField.cpp:33
This file offers overloads of toIce() and fromIce() functions for STL container types.
std::shared_ptr< CppWriter > CppWriterPtr
Definition CppWriter.h:35