CppCtor.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 "CppCtor.h"
25 
26 #include <boost/format.hpp>
27 
28 #include <SimoxUtility/algorithm/string/string_tools.h>
29 
32 
33 namespace armarx
34 {
35  CppCtor::CppCtor(const std::string& header)
36  {
37  this->header = header;
38  }
39 
40  CppCtor::CppCtor(const std::string& header, const CppBlockPtr& b)
41  {
42  this->header = header;
43  this->block = b;
44  }
45 
46  void
47  CppCtor::addInitListEntries(const std::vector<std::pair<std::string, std::string>>& list)
48  {
49  for (const auto& [target, expr] : list)
50  {
51  addInitListEntry(target, expr);
52  }
53  }
54 
55  void
56  CppCtor::addInitListEntry(const std::string& target, const std::string& expr)
57  {
58  this->initList.push_back(boost::str(boost::format("%s(%s)") % target % expr));
59  }
60 
61  void
62  CppCtor::addLine(const std::string& line)
63  {
64  if (!block)
65  {
66  this->block.reset(new CppBlock());
67  }
68  block->addLine(line);
69  }
70 
71  void
72  CppCtor::addLine(const boost::basic_format<char>& line)
73  {
74  if (!block)
75  {
76  this->block.reset(new CppBlock());
77  }
78  block->addLine(line);
79  }
80 
81  void
83  {
84  block = b;
85  }
86 
89  {
90  return block;
91  }
92 
93  void
95  {
96  writer->body.line(header);
97 
98  if (simox::alg::ends_with(simox::alg::trim_copy(header), ";")) // its a protoype
99  {
100  ARMARX_CHECK(initList.empty());
101  ARMARX_CHECK(!enforceBlockGeneration);
102  ARMARX_CHECK(!block);
103  return;
104  }
105 
106  for (size_t i = 0; i < initList.size(); i++)
107  {
108  writer->body.line(boost::str(boost::format("%s%s%s") % (i == 0 ? ": " : " ") %
109  initList.at(i) % (i < initList.size() - 1 ? "," : "")),
110  1);
111  }
112 
113  auto writeBlock = [this, writer]()
114  {
115  if (block)
116  {
117  block->writeCpp(writer);
118  }
119  else
120  {
121  CppBlockPtr b = std::make_shared<CppBlock>();
122  b->writeCpp(writer);
123  }
124  };
125 
126  //if (enforceBlockGeneration)
127  //{
128  // writeBlock();
129  //}
130  //else if (block || initList.size() > 0)
131  //{
132  writeBlock();
133  //}
134  }
135 
136  void
137  CppCtor::setEnforceBlockGeneration(const bool enforceBlockGeneration)
138  {
139  this->enforceBlockGeneration = enforceBlockGeneration;
140  }
141 } // namespace armarx
str
std::string str(const T &t)
Definition: UserAssistedSegmenterGuiWidgetController.cpp:43
LocalException.h
list
list(APPEND SOURCES ${QT_RESOURCES}) set(COMPONENT_LIBS ArmarXGui ArmarXCoreObservers ArmarXCoreEigen3Variants PlotterController $
Definition: CMakeLists.txt:49
CppCtor.h
boost::target
Vertex target(const detail::edge_base< Directed, Vertex > &e, const PCG &)
Definition: point_cloud_graph.h:668
armarx::CppBlockPtr
std::shared_ptr< CppBlock > CppBlockPtr
Definition: CppBlock.h:37
armarx::CppBlock
Definition: CppBlock.h:72
ARMARX_CHECK
#define ARMARX_CHECK(expression)
Shortcut for ARMARX_CHECK_EXPRESSION.
Definition: ExpressionException.h:82
armarx::CppCtor::addInitListEntries
void addInitListEntries(const std::vector< std::pair< std::string, std::string >> &)
Definition: CppCtor.cpp:47
armarx::CppCtor::writeCpp
void writeCpp(const CppWriterPtr &writer)
Definition: CppCtor.cpp:94
armarx::CppCtor::CppCtor
CppCtor(const std::string &header)
Definition: CppCtor.cpp:35
armarx::CppCtor::addLine
void addLine(const std::string &line)
Definition: CppCtor.cpp:62
armarx::CppCtor::setBlock
void setBlock(const CppBlockPtr &)
Definition: CppCtor.cpp:82
ExpressionException.h
armarx::ends_with
bool ends_with(const std::string &haystack, const std::string &needle)
Definition: StringHelpers.cpp:53
armarx::CppCtor::setEnforceBlockGeneration
void setEnforceBlockGeneration(bool enforceBlockGeneration)
Definition: CppCtor.cpp:137
armarx::CppWriterPtr
std::shared_ptr< CppWriter > CppWriterPtr
Definition: CppWriter.h:35
armarx::CppCtor::addInitListEntry
void addInitListEntry(const std::string &target, const std::string &expr)
Definition: CppCtor.cpp:56
armarx::CppCtor::getBlock
CppBlockPtr getBlock() const
Definition: CppCtor.cpp:88
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27