MetaWriter.h
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 #pragma once
25 
26 #include <string>
27 #include <sstream>
28 #include <memory>
29 #include <vector>
30 
31 // Simox
32 #include <SimoxUtility/algorithm/string.h>
33 
34 namespace armarx
35 {
36  class MetaWriter;
37  using MetaWriterPtr = std::shared_ptr<MetaWriter>;
38 
39  class Lines
40  {
41  public:
43 
44  std::string name;
45  std::stringstream ss;
46  std::vector<std::string> lines;
47  int indent = 0;
48 
49  Lines() = delete;
50  Lines(const std::string&, const std::string& = " ", const LineType = LineType::Empty);
51 
52  void startBlock();
53  void startBlock(const std::string& line);
54  void endBlock();
55  void endBlock(const std::string& line);
56  void endBlockComment(std::string comment);
57 
58  void line();
59  void line(const std::string& line, int indentDelta = 0);
60  void lineCheckDuplicate(const std::string& line, int indentDelta = 0);
61  void enforceEmptyLine();
62 
64 
65  private:
66  void lineInternal(const std::string& line, int indent);
67 
68  private:
69  std::string indentChars;
70  LineType lastLineType;
71  };
72 
73  class MetaWriter
74  {
75  public:
76 
77 
78  MetaWriter(const std::string& doc);
79  virtual ~MetaWriter() = default;
80 
81  void lineHeader();
82  void lineFooter();
83 
84  std::string getString();
85 
86  static void ConvertToTextWithMaxWidth(unsigned int maxTextWidth, const std::vector<std::string>& docLines, std::vector<std::string>& linesOut);
87 
88  public:
92 
93  protected:
94  std::string fileDoc;
95  };
96 }
97 
armarx::MetaWriter::header
Lines header
Definition: MetaWriter.h:89
armarx::Lines::startBlock
void startBlock()
Definition: MetaWriter.cpp:34
armarx::Lines::endBlockComment
void endBlockComment(std::string comment)
Definition: MetaWriter.cpp:63
armarx::MetaWriter::~MetaWriter
virtual ~MetaWriter()=default
armarx::MetaWriter::MetaWriter
MetaWriter(const std::string &doc)
Definition: MetaWriter.cpp:147
armarx::Lines::LineType
LineType
Definition: MetaWriter.h:42
armarx::Lines::LineType::Normal
@ Normal
armarx::Lines::LineType::Empty
@ Empty
armarx::Lines::ss
std::stringstream ss
Definition: MetaWriter.h:45
armarx::Lines::lineCheckDuplicate
void lineCheckDuplicate(const std::string &line, int indentDelta=0)
Definition: MetaWriter.cpp:90
armarx::Lines::Lines
Lines()=delete
armarx::Lines
Definition: MetaWriter.h:39
armarx::Lines::line
void line()
Definition: MetaWriter.cpp:115
armarx::Lines::LineType::StartBlock
@ StartBlock
armarx::Lines::indent
int indent
Definition: MetaWriter.h:47
armarx::MetaWriter::footer
Lines footer
Definition: MetaWriter.h:91
armarx::MetaWriter::ConvertToTextWithMaxWidth
static void ConvertToTextWithMaxWidth(unsigned int maxTextWidth, const std::vector< std::string > &docLines, std::vector< std::string > &linesOut)
Definition: MetaWriter.cpp:155
armarx::MetaWriter::fileDoc
std::string fileDoc
Definition: MetaWriter.h:94
armarx::Lines::enforceEmptyLine
void enforceEmptyLine()
Definition: MetaWriter.cpp:111
armarx::Lines::endBlock
void endBlock()
Definition: MetaWriter.cpp:49
armarx::MetaWriterPtr
std::shared_ptr< MetaWriter > MetaWriterPtr
Definition: MetaWriter.h:37
armarx::MetaWriter::lineFooter
void lineFooter()
armarx::Lines::LineType::EndBlock
@ EndBlock
armarx::MetaWriter::body
Lines body
Definition: MetaWriter.h:90
armarx::Lines::lines
std::vector< std::string > lines
Definition: MetaWriter.h:46
armarx::MetaWriter::getString
std::string getString()
Definition: MetaWriter.cpp:170
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::Lines::getLastLineType
Lines::LineType getLastLineType()
Definition: MetaWriter.cpp:131
armarx::MetaWriter::lineHeader
void lineHeader()
armarx::MetaWriter
Definition: MetaWriter.h:73
armarx::Lines::name
std::string name
Definition: MetaWriter.h:44