Changeset 10294


Ignore:
Timestamp:
Apr 7, 2011, 8:42:34 AM (9 years ago)
Author:
tbretz
Message:
AddTransitions and AddConfiguration now return a reference; AddStateName now accepts also an explanatory string; Added GetStateDesc to retrieve this string
Location:
trunk/FACT++/src
Files:
2 edited

Legend:

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

    r10289 r10294  
    472472//!    received commands is properly extracted. No check is done.
    473473//
    474 EventImp *StateMachineImp::AddTransition(int targetstate, const char *name, const char *states, const char *fmt)
     474EventImp &StateMachineImp::AddTransition(int targetstate, const char *name, const char *states, const char *fmt)
    475475{
    476476    EventImp *evt = CreateEvent(targetstate, name, fmt);
     
    483483    fListOfEvents.push_back(evt);
    484484
    485     return evt;
     485    return *evt;
    486486}
    487487
     
    507507//!    by this command.
    508508//
    509 EventImp *StateMachineImp::AddTransition(int targetstate, const char *name, int s1, int s2, int s3, int s4, int s5)
     509EventImp &StateMachineImp::AddTransition(int targetstate, const char *name, int s1, int s2, int s3, int s4, int s5)
    510510{
    511511    return AddTransition(targetstate, name, Form("%d %d %d %d %d", s1, s2, s3, s4, s5).c_str(), "");
     
    539539//!    by this command.
    540540//
    541 EventImp *StateMachineImp::AddTransition(int targetstate, const char *name, const char *fmt, int s1, int s2, int s3, int s4, int s5)
     541EventImp &StateMachineImp::AddTransition(int targetstate, const char *name, const char *fmt, int s1, int s2, int s3, int s4, int s5)
    542542{
    543543    return AddTransition(targetstate, name, Form("%d %d %d %d %d", s1, s2, s3, s4, s5).c_str(), fmt);
     
    566566//!    received commands is properly extracted. No check is done.
    567567//!
    568 EventImp *StateMachineImp::AddConfiguration(const char *name, const char *states, const char *fmt)
     568EventImp &StateMachineImp::AddConfiguration(const char *name, const char *states, const char *fmt)
    569569{
    570570    return AddTransition(-1, name, states, fmt);
     
    587587//!    by this command.
    588588//
    589 EventImp *StateMachineImp::AddConfiguration(const char *name, int s1, int s2, int s3, int s4, int s5)
     589EventImp &StateMachineImp::AddConfiguration(const char *name, int s1, int s2, int s3, int s4, int s5)
    590590{
    591591    return AddTransition(-1, name, s1, s2, s3, s4, s5);
     
    614614//!    by this command.
    615615//
    616 EventImp *StateMachineImp::AddConfiguration(const char *name, const char *fmt, int s1, int s2, int s3, int s4, int s5)
     616EventImp &StateMachineImp::AddConfiguration(const char *name, const char *fmt, int s1, int s2, int s3, int s4, int s5)
    617617{
    618618    return AddTransition(-1, name, fmt, s1, s2, s3, s4, s5);
     
    634634//! @todo  FIX THE DOCU
    635635//
    636 void StateMachineImp::AddStateName(const int state, const std::string &name)
    637 {
    638     if (fStateNames[state].empty())
    639         fStateNames[state] = name;
     636void StateMachineImp::AddStateName(const int state, const std::string &name, const std::string &doc)
     637{
     638    if (fStateNames[state].first.empty())
     639        fStateNames[state] = make_pair(name, doc);
    640640}
    641641
     
    652652const string StateMachineImp::GetStateName(int state) /*const*/
    653653{
    654     const string &str = fStateNames[state];
     654    const string &str = fStateNames[state].first;
    655655    return str.empty() ? Form("%d", state) : str;
     656}
     657
     658const string StateMachineImp::GetStateDoc(int state) /*const*/
     659{
     660    return fStateNames[state].second;
    656661}
    657662
     
    673678const string StateMachineImp::GetStateDescription(int state) /*const*/
    674679{
    675     const string &str = fStateNames[state];
     680    const string &str = GetStateName(state);
    676681    return str.empty() ? Form("%d", state) : (str+Form("[%d]", state));
    677682}
  • trunk/FACT++/src/StateMachineImp.h

    r10276 r10294  
    3232
    3333    /// Human readable names associated with the states
    34     std::map<const int, std::string> fStateNames;
     34    std::map<const int, std::pair<std::string, std::string>> fStateNames;
    3535
    3636    std::vector<EventImp*> fListOfEvents; /// List of available commands as setup by user
     
    7070    virtual std::string SetCurrentState(int state, const char *txt="", const std::string &cmd="");
    7171
    72     EventImp *AddTransition(int targetstate, const char *name, const char *states, const char *fmt);
    73     EventImp *AddTransition(int targetstate, const char *name, int s1=-1, int s2=-1, int s3=-1, int s4=-1, int s5=-1);
    74     EventImp *AddTransition(int targetstate, const char *name, const char *fmt, int s1=-1, int s2=-1, int s3=-1, int s4=-1, int s5=-1);
    75 
    76     EventImp *AddConfiguration(const char *name, const char *states, const char *fmt);
    77     EventImp *AddConfiguration(const char *name, int s1=-1, int s2=-1, int s3=-1, int s4=-1, int s5=-1);
    78     EventImp *AddConfiguration(const char *name, const char *fmt, int s1=-1, int s2=-1, int s3=-1, int s4=-1, int s5=-1);
    79 
    80     void AddStateName(const int state, const std::string &name);
     72    EventImp &AddTransition(int targetstate, const char *name, const char *states, const char *fmt);
     73    EventImp &AddTransition(int targetstate, const char *name, int s1=-1, int s2=-1, int s3=-1, int s4=-1, int s5=-1);
     74    EventImp &AddTransition(int targetstate, const char *name, const char *fmt, int s1=-1, int s2=-1, int s3=-1, int s4=-1, int s5=-1);
     75
     76    EventImp &AddConfiguration(const char *name, const char *states, const char *fmt);
     77    EventImp &AddConfiguration(const char *name, int s1=-1, int s2=-1, int s3=-1, int s4=-1, int s5=-1);
     78    EventImp &AddConfiguration(const char *name, const char *fmt, int s1=-1, int s2=-1, int s3=-1, int s4=-1, int s5=-1);
     79
     80    void AddStateName(const int state, const std::string &name, const std::string &doc="");
    8181
    8282public:
     
    123123    const std::string GetStateName(int state) /*const*/;
    124124    const std::string GetStateName() { return GetStateName(fCurrentState); }
     125
     126    const std::string GetStateDesc(int state) /*const*/;
     127    const std::string GetStateDesc() { return GetStateDesc(fCurrentState); }
    125128
    126129    const std::string GetStateDescription(int state) /*const*/;
Note: See TracChangeset for help on using the changeset viewer.