DoxDoc.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 "DoxDoc.h"
25 #include "DoxLine.h"
26 #include "DoxTable.h"
27 #include "DoxTransitiongraph.h"
28 
31 
32 #include <SimoxUtility/algorithm/string/string_tools.h>
33 
34 
35 using namespace armarx;
37 {
38 }
39 
41 {
42  entries.push_back(entry);
43 }
44 
46 {
47  addLine("");
48 }
49 
51 {
52  writer->body.line("/**");
53 
54  for (DoxEntryPtr entry : entries)
55  {
56  std::string doc = entry->getDoxString();
57  std::string delimiters = "\n";
58  std::vector<std::string> doclines = simox::alg::split(doc, delimiters);
59 
60  for (std::string line : doclines)
61  {
62  writer->body.line(" * " + line);
63  }
64 
65  }
66 
67  writer->body.line("*/");
68 }
69 
70 
71 void armarx::DoxDoc::addLine(const std::string& line)
72 {
73  DoxEntryPtr entry(new DoxLine(line));
74  addEntry(entry);
75 
76 }
77 
78 
80 {
81  std::vector<std::string> header;
82  header.push_back("Name");
83  header.push_back("Type");
84  header.push_back("Default value");
85  header.push_back("Description");
86 
87  DoxTablePtr table = DoxTablePtr(new DoxTable(header));
88 
89 
90  for (RapidXmlReaderNode parameter : parameters.nodes())
91  {
92  std::vector<std::string> row;
93  row.push_back(parameter.attribute_value("name"));
94  std::string nestedType = parameter.attribute_value("type");
95 
96  if (variantInfo->getNestedHumanNameFromBaseName(nestedType).compare("") != 0)
97  {
98  row.push_back(variantInfo->getNestedHumanNameFromBaseName(nestedType));
99  }
100  else
101  {
102  row.push_back(nestedType);
103  }
104 
105  JSONObjectPtr jsonObject = new JSONObject(communicator);
106  std::string defaultValue = parameter.attribute_value_or_default("default", "");
107 
108  if (defaultValue.size() > 0)
109  {
110  try
111  {
112  jsonObject->fromString(defaultValue);
113  SerializablePtr obj = jsonObject->deserializeIceObject();
114  VariantContainerBasePtr result = VariantContainerBasePtr::dynamicCast(obj);
115  std::string resultString = result->toString();
116  resultString = simox::alg::replace_all(resultString, "\n", "<br>");
117  row.push_back(resultString);
118  }
119  catch (Ice::Exception& e)
120  {
121  ARMARX_WARNING_S << "Cannot deserialize defaultValue of parameter " << parameter.attribute_value("name") << ": \"" << defaultValue << "\"\n" << e.ice_id() << ":\n" << e.what() << "\n" << e.ice_stackTrace();
122  row.push_back(" ");
123  }
124  }
125  else
126  {
127  row.push_back(" ");
128  }
129 
130  row.push_back(parameter.attribute_value_or_default("description", " "));
131 
132  table->addRow(row);
133  }
134 
135  addEntry(table);
136 }
137 
138 
140 {
142 
143  for (RapidXmlReaderNode transition : transitions.nodes())
144  {
145  if (transition.has_attribute("from") && transition.has_attribute("to") && transition.has_attribute("eventName"))
146  {
147  graph->addTransition(DoxTransitionPtr(new DoxTransition(transition.attribute_value("from"), transition.attribute_value("to"), transition.attribute_value("eventName"))));
148  }
149  }
150 
151  addEntry(graph);
152 }
armarx::DoxTransitionGraphPtr
std::shared_ptr< DoxTransitionGraph > DoxTransitionGraphPtr
Definition: DoxTransitiongraph.h:63
armarx::DoxLine
Definition: DoxLine.h:38
DoxTable.h
JSONObject.h
armarx::DoxDoc::addEntry
void addEntry(DoxEntryPtr entry)
Definition: DoxDoc.cpp:40
armarx::DoxDoc::addLine
void addLine()
Definition: DoxDoc.cpp:45
armarx::JSONObject
The JSONObject class is used to represent and (de)serialize JSON objects.
Definition: JSONObject.h:43
DoxTransitiongraph.h
armarx::DoxTable
Definition: DoxTable.h:38
armarx::DoxTablePtr
std::shared_ptr< DoxTable > DoxTablePtr
Definition: DoxTable.h:35
armarx::DoxEntryPtr
std::shared_ptr< DoxEntry > DoxEntryPtr
Definition: DoxEntry.h:32
IceInternal::Handle< ::Ice::Communicator >
DoxLine.h
armarx::DoxDoc::DoxDoc
DoxDoc()
Definition: DoxDoc.cpp:36
armarx::RapidXmlReaderNode
Definition: RapidXmlReader.h:68
ARMARX_WARNING_S
#define ARMARX_WARNING_S
Definition: Logging.h:206
armarx::DoxTransitionGraph
Definition: DoxTransitiongraph.h:65
DoxDoc.h
armarx::DoxDoc::addParameterTable
void addParameterTable(const RapidXmlReaderNode &parameters, VariantInfoPtr variantInfo, Ice::CommunicatorPtr communicator)
Definition: DoxDoc.cpp:79
armarx::VariantInfoPtr
std::shared_ptr< VariantInfo > VariantInfoPtr
Definition: VariantInfo.h:39
armarx::RapidXmlReaderNode::nodes
std::vector< RapidXmlReaderNode > nodes(const char *name=nullptr) const
Definition: RapidXmlReader.h:158
armarx::DoxDoc::writeDoc
void writeDoc(CppWriterPtr writer)
Definition: DoxDoc.cpp:50
armarx::CppWriterPtr
std::shared_ptr< CppWriter > CppWriterPtr
Definition: CppWriter.h:35
Logging.h
armarx::DoxDoc::addTransitionGraph
void addTransitionGraph(const RapidXmlReaderNode &transitions)
Definition: DoxDoc.cpp:139
armarx::DoxTransitionPtr
std::shared_ptr< DoxTransition > DoxTransitionPtr
Definition: DoxTransitiongraph.h:35
armarx::DoxTransition
Definition: DoxTransitiongraph.h:37
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::split
std::vector< std::string > split(const std::string &source, const std::string &splitBy, bool trimElements=false, bool removeEmptyElements=false)
Definition: StringHelpers.cpp:36