FACT++  1.0
Description.cc
Go to the documentation of this file.
1 // **************************************************************************
40 // **************************************************************************
41 #include "Description.h"
42 
43 #include <sstream>
44 
45 #include "tools.h"
46 
47 using namespace std;
48 using namespace Tools;
49 
50 // --------------------------------------------------------------------------
51 //
62 //
63 Description::Description(const string &n, const string &c, const string &u)
64  : name(Trim(n)), comment(Trim(c)), unit(Trim(u))
65 {
66 }
67 
68 // --------------------------------------------------------------------------
69 //
81 //
82 vector<Description> Description::SplitDescription(const string &buffer)
83 {
84  const size_t p0 = buffer.find_first_of('=');
85 
86  const string svc = buffer.substr(0, p0);
87  const string desc = buffer.substr(p0+1);
88 
89  const size_t p = desc.find_first_of('|');
90 
91  // Extract a general description
92  const string d = Trim(desc.substr(0, p));
93 
94  vector<Description> vec;
95  vec.emplace_back(svc, d);
96 
97  if (p==string::npos)
98  return vec;
99 
100  string buf;
101  stringstream stream(desc.substr(p+1));
102  while (getline(stream, buf, '|'))
103  {
104  if (buf.empty())
105  continue;
106 
107  const size_t p1 = buf.find_first_of(':');
108 
109  const string comment = p1==string::npos ? "" : buf.substr(p1+1);
110  if (p1!=string::npos)
111  buf.erase(p1);
112 
113  const size_t p2 = buf.find_last_of('[');
114  const size_t p3 = buf.find_last_of(']');
115 
116  const bool hasunit = p2<p3 && p2!=string::npos;
117 
118  const string unit = hasunit ? buf.substr(p2+1, p3-p2-1) : "";
119  const string name = hasunit ? buf.substr(0, p2) : buf;
120 
121  vec.emplace_back(name, comment, unit);
122  }
123 
124  return vec;
125 }
126 
127 
128 // --------------------------------------------------------------------------
129 //
139 //
140 string Description::GetHtmlDescription(const vector<Description> &vec)
141 {
142  stringstream str;
143  str << "<H3>" << vec[0].name << "</H3>";
144 
145  str << "Usage:";
146  for (vector<Description>::const_iterator i=vec.begin()+1; i!=vec.end(); i++)
147  str << "&nbsp;<font color='maroon'>&lt;" << i->name << "&gt;</font>";
148 
149  if (vec.size()==1)
150  str << " &lt;no arguments&gt;";
151 
152  str << "<P>" << vec[0].comment << "<P>";
153 
154  str << "<table>";
155 
156  for (vector<Description>::const_iterator i=vec.begin()+1; i!=vec.end(); i++)
157  {
158  str << "<tr>"
159  "<td><font color='maroon'>" << i->name << "</font>";
160 
161  if (i->unit.empty() && !i->comment.empty() && !i->name.empty())
162  str << ':';
163 
164  str << "</td>";
165 
166  if (!i->unit.empty())
167  str << "<td><font color='green'>[" << i->unit << "]</font>";
168 
169  if (!i->unit.empty() && !i->comment.empty())
170  str << ':';
171 
172  str <<
173  "</td>"
174  "<td><font color='navy'>" << i->comment << "</font></td>"
175  "</tr>";
176  }
177 
178  str << "</table>";
179 
180  return str.str();
181 }
std::string unit
Definition: Description.h:11
int i
Definition: db_dim_client.c:21
char str[80]
Definition: test_client.c:7
STL namespace.
static std::string GetHtmlDescription(const std::vector< Description > &vec)
Definition: Description.cc:140
Definition: tools.h:8
static std::vector< Description > SplitDescription(const std::string &buffer)
Definition: Description.cc:82
std::string name
Definition: Description.h:9
int buffer[BUFFSIZE]
Definition: db_dim_client.c:14
std::string comment
Definition: Description.h:10
if(extraDns) new Dns
std::string Trim(const std::string &str)
Definition: tools.cc:68
Description(const std::string &n, const std::string &c, const std::string &u="")
Definition: Description.cc:63