Changeset 10381


Ignore:
Timestamp:
04/18/11 10:58:17 (14 years ago)
Author:
tbretz
Message:
Turned comment and unit in constructor, added a function to return a html formatted list.
Location:
trunk/FACT++/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/FACT++/src/Description.cc

    r10349 r10381  
    4343#include <sstream>
    4444
     45#include "tools.h"
     46
    4547using namespace std;
     48
     49// --------------------------------------------------------------------------
     50//
     51//! Construct a Description object
     52//!
     53//! @param n
     54//!     Name of the Description, e.g. "temp"
     55//!
     56//! @param c
     57//!     Descriptive text of the Description, e.g. "Temperature of the moon"
     58//!
     59//! @param u
     60//!     Unit of the Description, e.g. "K"
     61//
     62Description::Description(const string &n, const string &c, const string &u)
     63    : name(Trim(n)), comment(Trim(c)), unit(Trim(u))
     64{
     65}
    4666
    4767// --------------------------------------------------------------------------
     
    7292
    7393    vector<Description> vec;
    74     vec.push_back(Description(svc, "", d));
     94    vec.push_back(Description(svc, d));
    7595
    7696    if (p==string::npos)
     
    98118        const string name = hasunit ? buf.substr(0, p2) : buf;
    99119
    100         vec.push_back(Description(name, unit, comment));
     120        vec.push_back(Description(name, comment, unit));
    101121    }
    102122
    103123    return vec;
    104124}
     125
     126
     127// --------------------------------------------------------------------------
     128//
     129//! Returns a string with an html formatted text containing the descriptions
     130//! as returned by SplitDescription
     131//!
     132//! @param vec
     133//!     vector of Description for the individual arguments. First
     134//!     element is the global description of the command or service.
     135//!
     136//! @returns
     137//!     string with html formatted text
     138//
     139string Description::GetHtmlDescription(const vector<Description> &vec)
     140{
     141    stringstream str;
     142    str << '|';
     143
     144    str << "<H3>" << vec[0].name << "</H3>";
     145
     146    str << "Usage:";
     147    for (vector<Description>::const_iterator i=vec.begin()+1; i!=vec.end(); i++)
     148        str << "&nbsp;<font color='maroon'>&lt;" << i->name <<    "&gt;</font>";
     149
     150    if (vec.size()==1)
     151        str << " &lt;no arguments&gt;";
     152
     153    str << "<P>" << vec[0].comment << "<P>";
     154
     155    str << "<table>";
     156
     157    for (vector<Description>::const_iterator i=vec.begin()+1; i!=vec.end(); i++)
     158    {
     159        str << "<tr>"
     160            "<td><font color='maroon'>" << i->name <<     "</font>";
     161
     162        if (i->unit.empty() && !i->comment.empty() && !i->name.empty())
     163            str << ':';
     164
     165        str << "</td>";
     166
     167        if (!i->unit.empty())
     168            str << "<td><font color='green'>[" << i->unit <<    "]</font>";
     169
     170        if (!i->unit.empty() && !i->comment.empty())
     171            str << ':';
     172
     173        str <<
     174            "</td>"
     175            "<td><font color='navy'>"   << i->comment <<  "</font></td>"
     176            "</tr>";
     177    }
     178
     179    str << "</table>";
     180
     181    return str.str();
     182}
  • trunk/FACT++/src/Description.h

    r10342 r10381  
    55#include <vector>
    66
    7 #include "tools.h"
    8 
    97struct Description
    108{
    119    std::string name;
     10    std::string comment;
    1211    std::string unit;
    13     std::string comment;
    1412
    1513    static std::vector<Description> SplitDescription(const std::string &buffer);
     14    static std::string GetHtmlDescription(const std::vector<Description> &vec);
    1615
    17     Description(const std::string &n, const std::string &u, const std::string &c)
    18         : name(Trim(n)), unit(Trim(u)), comment(Trim(c)) { }
     16    Description(const std::string &n, const std::string &c, const std::string &u="");
    1917};
    2018
Note: See TracChangeset for help on using the changeset viewer.