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
33using namespace armarx;
34
35CppMethod::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
44void
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
93void
94CppMethod::addLine(const std::string& line)
95{
96 if (!block)
97 {
98 this->block.reset(new CppBlock());
99 }
100 block->addLine(line);
101}
102
103void
104CppMethod::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
113void
115{
116 if (!block)
117 {
118 this->block.reset(new CppBlock());
119 }
120 block->addBlock(new_block);
121}
122
123void
125{
126 block = new_block;
127}
128
129void
130CppMethod::setCompact(const bool compact)
131{
132 this->compact = compact;
133}
134
135void
136CppMethod::setEnforceBlockGeneration(const bool enforceBlockGeneration)
137{
138 this->enforceBlockGeneration = enforceBlockGeneration;
139}
void setBlock(const CppBlockPtr &block)
void writeCpp(const CppWriterPtr &writer)
Definition CppMethod.cpp:45
void addLine(const std::string &line)
Definition CppMethod.cpp:94
void setEnforceBlockGeneration(bool enforceBlockGeneration)
void setCompact(bool compact)
void addBlock(const CppBlockPtr &block)
CppMethod(const std::string &header, const std::string &doc="", const bool enforceBlockGeneration=false)
Definition CppMethod.cpp:35
#define ARMARX_CHECK(expression)
Shortcut for ARMARX_CHECK_EXPRESSION.
This file offers overloads of toIce() and fromIce() functions for STL container types.
std::shared_ptr< CppWriter > CppWriterPtr
Definition CppWriter.h:35
std::shared_ptr< CppBlock > CppBlockPtr
Definition CppBlock.h:37