// ************************************************************************** /** @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 using namespace std; // -------------------------------------------------------------------------- // //! 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