CppMethod.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 "CppMethod.h"
25 
26 #include <boost/format.hpp>
27 
28 #include <SimoxUtility/algorithm/string/string_tools.h>
29 
32 
33 using namespace armarx;
34 
35 CppMethod::CppMethod(const std::string& header,
36  const std::string& doc,
37  const bool enforceBlockGeneration) :
38  header(header), // may be suffixed with ;
39  doc(doc),
40  enforceBlockGeneration(enforceBlockGeneration)
41 {
42 }
43 
44 void
46 {
47  if (!doc.empty())
48  {
49  std::string delimiters = "\n";
50  std::vector<std::string> doclines = simox::alg::split(doc, delimiters);
51  writer->body.line("/**");
52 
53  for (auto& line : doclines)
54  {
55  writer->body.line(" * " + line);
56  }
57 
58  writer->body.line(" */");
59  }
60 
61  writer->body.line(header);
62 
63  if (simox::alg::ends_with(simox::alg::trim_copy(header), ";"))
64  {
65  ARMARX_CHECK(!enforceBlockGeneration);
66  ARMARX_CHECK(!block);
67  return;
68  }
69 
70  auto writeBlock = [this, writer]()
71  {
72  if (block)
73  {
74  block->writeCpp(writer);
75  }
76  else
77  {
78  CppBlockPtr b = std::make_shared<CppBlock>();
79  b->writeCpp(writer);
80  }
81  };
82 
83  //if (enforceBlockGeneration)
84  //{
85  writeBlock();
86  //}
87  //else if (block)
88  //{
89  // block->writeCpp(writer);
90  //}
91 }
92 
93 void
94 CppMethod::addLine(const std::string& line)
95 {
96  if (!block)
97  {
98  this->block.reset(new CppBlock());
99  }
100  block->addLine(line);
101 }
102 
103 void
104 CppMethod::addLine(const boost::basic_format<char>& line)
105 {
106  if (!block)
107  {
108  this->block.reset(new CppBlock());
109  }
110  block->addLine(line);
111 }
112 
113 void
115 {
116  if (!block)
117  {
118  this->block.reset(new CppBlock());
119  }
120  block->addBlock(new_block);
121 }
122 
123 void
125 {
126  block = new_block;
127 }
128 
129 void
130 CppMethod::setCompact(const bool compact)
131 {
132  this->compact = compact;
133 }
134 
135 void
136 CppMethod::setEnforceBlockGeneration(const bool enforceBlockGeneration)
137 {
138  this->enforceBlockGeneration = enforceBlockGeneration;
139 }
armarx::CppMethod::writeCpp
void writeCpp(const CppWriterPtr &writer)
Definition: CppMethod.cpp:45
armarx::CppMethod::addBlock
void addBlock(const CppBlockPtr &block)
Definition: CppMethod.cpp:114
CppMethod.h
armarx::CppBlockPtr
std::shared_ptr< CppBlock > CppBlockPtr
Definition: CppBlock.h:37
armarx::CppBlock
Definition: CppBlock.h:72
armarx::CppMethod::setCompact
void setCompact(bool compact)
Definition: CppMethod.cpp:130
ARMARX_CHECK
#define ARMARX_CHECK(expression)
Shortcut for ARMARX_CHECK_EXPRESSION.
Definition: ExpressionException.h:82
armarx::CppMethod::setBlock
void setBlock(const CppBlockPtr &block)
Definition: CppMethod.cpp:124
armarx::CppMethod::CppMethod
CppMethod(const std::string &header, const std::string &doc="", const bool enforceBlockGeneration=false)
Definition: CppMethod.cpp:35
ExpressionException.h
armarx::CppMethod::addLine
void addLine(const std::string &line)
Definition: CppMethod.cpp:94
armarx::ends_with
bool ends_with(const std::string &haystack, const std::string &needle)
Definition: StringHelpers.cpp:53
armarx::CppWriterPtr
std::shared_ptr< CppWriter > CppWriterPtr
Definition: CppWriter.h:35
Logging.h
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
armarx::split
std::vector< std::string > split(const std::string &source, const std::string &splitBy, bool trimElements=false, bool removeEmptyElements=false)
Definition: StringHelpers.cpp:38
armarx::CppMethod::setEnforceBlockGeneration
void setEnforceBlockGeneration(bool enforceBlockGeneration)
Definition: CppMethod.cpp:136