CppBlock.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 "CppBlock.h"
25
26#include <boost/format.hpp>
27
28using namespace armarx;
29
33
34CppBlockStringEntry::CppBlockStringEntry(const std::string& s) : line(s)
35{
36}
37
39{
40}
41
42void
44{
45 writer->body.line(line);
46}
47
48void
50{
51 nestedBlock->writeCpp(writer);
52}
53
54void
56{
57 writer->body.startBlock();
58 for (const auto& entry : entries)
59 {
60 entry->writeCpp(writer);
61 }
62 writer->body.endBlock();
63}
64
65std::string
67{
68 return line;
69}
70
71std::string
73{
74 return nestedBlock->getAsSingleLine();
75}
76
77std::string
79{
80 std::stringstream ss;
81 ss << "{ ";
82
83 for (const auto& entry : entries)
84 {
85 ss << entry->getAsSingleLine() << " ";
86 }
87
88 ss << "}";
89 return ss.str();
90}
91
92void
93CppBlock::addLine(const std::string& line)
94{
96 entries.push_back(t);
97}
98
99void
100CppBlock::addLine(const boost::basic_format<char>& line)
101{
102 addLine(boost::str(line));
103}
104
105size_t
107{
108 return entries.size();
109}
110
111void
112CppBlock::addCommentLine(const std::string& line)
113{
114 addLine("//" + line);
115}
116
117void
118CppBlock::addCommentLine(const boost::basic_format<char>& line)
119{
120 addLine("//" + boost::str(line));
121}
122
123void
124CppBlock::addCommentLines(const std::vector<std::string>& lines)
125{
126 addLine("/*");
127 for (const auto& line : lines)
128 {
129 addLine(" * " + line);
130 }
131 addLine(" */");
132}
133
134void
135CppBlock::addCommentLines(const std::vector<boost::basic_format<char>>& lines)
136{
137 addLine("/*");
138 for (const auto& line : lines)
139 {
140 addLine(" * " + boost::str(line));
141 }
142 addLine(" */");
143}
144
145void
147{
149 entries.push_back(t);
150}
151
152void
154{
155 for (const auto& entry : block->entries)
156 {
157 addEntry(entry);
158 }
159}
160
161void
162CppBlock::addLineAsBlock(const std::string& line)
163{
164 CppBlockPtr b = std::make_shared<CppBlock>();
165 b->addLine(line);
166 this->addBlock(b);
167}
168
169void
171{
172 entries.push_back(entry);
173}
174
176CppBlock::MergeBlocks(const CppBlockPtr& block1, const CppBlockPtr& block2)
177{
178 CppBlockPtr ret = CppBlockPtr(new CppBlock());
179 for (const auto& entry : block1->entries)
180 {
181 ret->addEntry(entry);
182 }
183
184 for (const auto& entry : block2->entries)
185 {
186 ret->addEntry(entry);
187 }
188 return ret;
189}
virtual std::string getAsSingleLine() override
Definition CppBlock.cpp:72
virtual void writeCpp(const CppWriterPtr &writer) override
Definition CppBlock.cpp:49
CppBlockBlockEntry(const CppBlockPtr &)
Definition CppBlock.cpp:38
CppBlockStringEntry(const std::string &)
Definition CppBlock.cpp:34
virtual std::string getAsSingleLine() override
Definition CppBlock.cpp:66
virtual void writeCpp(const CppWriterPtr &writer) override
Definition CppBlock.cpp:43
void addLineAsBlock(const std::string &line)
Definition CppBlock.cpp:162
size_t size() const
Definition CppBlock.cpp:106
void addEntry(const CppBlockEntryPtr &entry)
Definition CppBlock.cpp:170
void addCommentLine(const std::string &line)
Definition CppBlock.cpp:112
void writeCpp(const CppWriterPtr &writer)
Definition CppBlock.cpp:55
void addLine(const std::string &line)
Definition CppBlock.cpp:93
void appendBlock(const CppBlockPtr &block)
Definition CppBlock.cpp:153
std::string getAsSingleLine()
Definition CppBlock.cpp:78
std::vector< CppBlockEntryPtr > entries
Definition CppBlock.h:99
void addBlock(const CppBlockPtr &block)
Definition CppBlock.cpp:146
void addCommentLines(const std::vector< std::string > &lines)
Definition CppBlock.cpp:124
static CppBlockPtr MergeBlocks(const CppBlockPtr &block1, const CppBlockPtr &block2)
Definition CppBlock.cpp:176
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
std::shared_ptr< CppBlockEntry > CppBlockEntryPtr
Definition CppBlock.h:40