Changeset 10295


Ignore:
Timestamp:
04/07/11 08:43:01 (14 years ago)
Author:
tbretz
Message:
Added operator() for easy configuration; Added fDescription for convenience; Added GetString and GetVector member functions
Location:
trunk/FACT++/src
Files:
2 edited

Legend:

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

    r10183 r10295  
    112112
    113113#include "Time.h"
     114#include "WindowLog.h"
    114115
    115116using namespace std;
     
    199200    const string str = GetName();
    200201    if (!str.empty())
    201         out << str;
     202        out << kBold << str;
    202203
    203204    const string fmt = GetFormat();
    204205    if (!fmt.empty())
    205         out << "[" << fmt << "]";
    206 
    207     out << ":";
     206        out << kBold << "[" << fmt << "]";
     207
     208    out << kReset << ":";
    208209
    209210    for (unsigned int i=0; i<fAllowedStates.size(); i++)
     
    231232        out << ")";
    232233    out << endl;
     234
     235    if (!fDescription.empty())
     236        out << "     " << fDescription << endl;
    233237}
    234238
  • trunk/FACT++/src/EventImp.h

    r10183 r10295  
    1414    std::vector<int> fAllowedStates; /// List of states in which this event is allowed
    1515
     16    std::string      fDescription;   /// A human readable description of the event
     17
    1618    /// http://www.boost.org/doc/libs/1_45_0/libs/bind/bind.html
    1719    boost::function<int(const EventImp &)> fFunction;
     
    2325    EventImp(const EventImp &cmd);
    2426
     27    // Description
     28    EventImp &SetDescription(const std::string &str) { fDescription=str; return *this; }
     29
    2530    // Function handling
    26     void AssignFunction(boost::function<int(const EventImp &)> func) { fFunction = func; }
     31    EventImp &AssignFunction(boost::function<int(const EventImp &)> func) { fFunction = func; return *this; }
    2732    bool HasFunc() const { return !fFunction.empty(); }
    2833    int ExecFunc() const { return HasFunc() ? fFunction(*this) : -1; }
     34
     35    // Configuration helper
     36    EventImp &operator()(boost::function<int(const EventImp &)> func) { return AssignFunction(func); }
     37    EventImp &operator()(const std::string str) { return SetDescription(str); }
     38    EventImp &operator()(const char *str) { return SetDescription(str); }
    2939
    3040    // Print contents
     
    5060
    5161    // Getter for all the data contained (name, format, data and time)
    52     short          GetShort()  const { return *reinterpret_cast<const short*>(GetData()); }
    53     unsigned short GetUShort() const { return *reinterpret_cast<const unsigned short*>(GetData()); }
    54     int            GetInt() const    { return *reinterpret_cast<const int*>(GetData()); }
    55     unsigned int   GetUInt() const   { return *reinterpret_cast<const unsigned int*>(GetData()); }
    56     float          GetFloat() const  { return *reinterpret_cast<const float*>(GetData()); }
    57     double         GetDouble() const { return *reinterpret_cast<const double*>(GetData()); }
    58     const char    *GetText() const   { return  reinterpret_cast<const char*>(GetData()); }
     62    short             GetShort()  const { return *reinterpret_cast<const short*>(GetData()); }
     63    unsigned short    GetUShort() const { return *reinterpret_cast<const unsigned short*>(GetData()); }
     64    int               GetInt() const    { return *reinterpret_cast<const int*>(GetData()); }
     65    unsigned int      GetUInt() const   { return *reinterpret_cast<const unsigned int*>(GetData()); }
     66    float             GetFloat() const  { return *reinterpret_cast<const float*>(GetData()); }
     67    double            GetDouble() const { return *reinterpret_cast<const double*>(GetData()); }
     68    const char       *GetText() const   { return  reinterpret_cast<const char*>(GetData()); }
     69    std::string       GetString() const { return std::string(GetText(), GetSize()); }
     70    std::vector<char> GetVector() const { return std::vector<char>(GetText(), GetText()+GetSize()); }
    5971
    6072};
Note: See TracChangeset for help on using the changeset viewer.