// ************************************************************************** /** @struct Description @brief A struct which stores a name, a unit and a comment To have proper descriptions of commands and services in the network (and later proper informations in the FITS files) this struct provides a simple storage for a name, a unit and a comment. Assume you want to write a descriptive string for a command with three arguments. It could look like this: COMMAND=Description|int[addr]:Address range (from - to)|val[byte]:Value to be set Description is a general description of the command or service itself, int and val are the names of the arguments (e.g. names of FITS columns), addr and byte have the meaning of a unit (e.g. unit of FITS column) and the text after the colon is a description of the arguments (e.g. comment of a FITS column). The description must not contain a line-break character \n. Such a string can then be converted with SplitDescription into a vector of Description objects, each containing the name, the unit and a comment indivdually. The first object will contain COMMAND as name and Description as comment. The unit will remain empty. You can omit either the name, the unit or the comment or any combination of them. The descriptions of the individual format strings are separated by a vertical line. If you want to enclose the name into []-braces (e.g. marking an optional argument in a dim command), you have add empty brackets for the units. For a suggestion for rules for the names please have a look at: http://heasarc.gsfc.nasa.gov/docs/heasarc/ofwg/docs/ofwg_recomm/r15.html For units please see: http://heasarc.gsfc.nasa.gov/docs/heasarc/ofwg/docs/general/ogip_93_001/ogip_93_001.html */ // ************************************************************************** #include "Description.h" #include #include "tools.h" using namespace std; // -------------------------------------------------------------------------- // //! Construct a Description object //! //! @param n //! Name of the Description, e.g. "temp" //! //! @param c //! Descriptive text of the Description, e.g. "Temperature of the moon" //! //! @param u //! Unit of the Description, e.g. "K" // Description::Description(const string &n, const string &c, const string &u) : name(Trim(n)), comment(Trim(c)), unit(Trim(u)) { } // -------------------------------------------------------------------------- // //! This function breaks down a descriptive string into its components. //! For details see class reference. //! //! @param buffer //! string which should be broekn into pieces //! //! @returns //! A vector containing all the descriptions found. //! The first entry contains the Description members name and comment, //! corresponding to the service or command name the Description //! list is for and its corresponding description. // vector Description::SplitDescription(const string &buffer) { const size_t p0 = buffer.find_first_of('='); const string svc = buffer.substr(0, p0); const string desc = buffer.substr(p0+1); const size_t p = desc.find_first_of('|'); // Extract a general description const string d = Trim(desc.substr(0, p)); vector vec; vec.push_back(Description(svc, d)); if (p==string::npos) return vec; string buf; stringstream stream(desc.substr(p+1)); while (getline(stream, buf, '|')) { if (buf.empty()) continue; const size_t p1 = buf.find_first_of(':'); const string comment = p1==string::npos ? "" : buf.substr(p1+1); if (p1!=string::npos) buf.erase(p1); const size_t p2 = buf.find_last_of('['); const size_t p3 = buf.find_last_of(']'); const bool hasunit = p2 &vec) { stringstream str; str << "

" << vec[0].name << "

"; str << "Usage:"; for (vector::const_iterator i=vec.begin()+1; i!=vec.end(); i++) str << " <" << i->name << ">"; if (vec.size()==1) str << " <no arguments>"; str << "

" << vec[0].comment << "

"; str << ""; for (vector::const_iterator i=vec.begin()+1; i!=vec.end(); i++) { str << "" ""; if (!i->unit.empty()) str << "" "" ""; } str << "
" << i->name << ""; if (i->unit.empty() && !i->comment.empty() && !i->name.empty()) str << ':'; str << "[" << i->unit << "]"; if (!i->unit.empty() && !i->comment.empty()) str << ':'; str << "" << i->comment << "
"; return str.str(); }