Changeset 14558 for trunk/FACT++/src


Ignore:
Timestamp:
11/05/12 12:02:02 (12 years ago)
Author:
tbretz
Message:
Slight modification to addining new states; updating states is now allowed, added a return value, compile the string which is send as description each time again.
Location:
trunk/FACT++/src
Files:
4 edited

Legend:

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

    r14489 r14558  
    9696//! Overwrite StateMachineImp::AddStateName. In addition to storing the
    9797//! state locally it is also propagated through Dim in the STATE_LIST
    98 //! service.
     98//! service. 
    9999//!
    100100//! @param state
     
    107107//!    A explanatory text describing the state
    108108//!
    109 void StateMachineDim::AddStateName(const int state, const std::string &name, const std::string &doc)
    110 {
     109bool StateMachineDim::AddStateName(const int state, const std::string &name, const std::string &doc)
     110{
     111    if (name.empty())
     112        return false;
     113
     114    const bool rc = HasState(state) || GetStateIndex(name)!=kSM_NotAvailable;
     115
    111116    StateMachineImp::AddStateName(state, name, doc);
    112117
    113     const string str0 = fDescriptionStates.itsData ? reinterpret_cast<char*>(fDescriptionStates.itsData) : "";
    114     const string str1 = to_string(state)+':'+name+'=';
    115 
    116     if (str0.find(str1)!=string::npos)
    117         return;
    118 
    119     fDescriptionStates.Update(str0+str1+doc+'\n');
     118    string str;
     119    for (auto it=fStateNames.begin(); it!=fStateNames.end(); it++)
     120        str += to_string(state)+':'+name+'='+doc+'\n';
     121
     122    fDescriptionStates.Update(str);
     123
     124    return rc;
    120125}
    121126
  • trunk/FACT++/src/StateMachineDim.h

    r14070 r14558  
    8787    int Write(const Time &time, const std::string &txt, int qos=kMessage);
    8888
    89     void AddStateName(const int state, const std::string &name, const std::string &doc="");
     89    bool AddStateName(const int state, const std::string &name, const std::string &doc="");
    9090};
    9191
  • trunk/FACT++/src/StateMachineImp.cc

    r14124 r14558  
    659659//!    A explanatory text describing the state
    660660//!
    661 void StateMachineImp::AddStateName(const int state, const std::string &name, const std::string &doc)
    662 {
    663     if (fStateNames[state].first.empty())
    664         fStateNames[state] = make_pair(name, doc);
     661bool StateMachineImp::AddStateName(const int state, const std::string &name, const std::string &doc)
     662{
     663    //auto it = fStateNames.find(state);
     664
     665    //if (/*it!=fStateNames.end() &&*/ !it->second.first.empty())
     666    //    return false;
     667
     668    fStateNames[state] = make_pair(name, doc);
     669    return true;
     670}
     671
     672// --------------------------------------------------------------------------
     673//
     674//! Get a state's index by its name.
     675//!
     676//! @param name
     677//!    Name of the state to search for
     678//!
     679//! @returns
     680//!    Index of the state if found, kSM_NotAvailable otherwise
     681//!
     682int StateMachineImp::GetStateIndex(const string &name) const
     683{
     684    for (auto it=fStateNames.begin(); it!=fStateNames.end(); it++)
     685        if (it->second.first==name)
     686            return it->first;
     687
     688    return kSM_NotAvailable;
    665689}
    666690
     
    682706    s << state;
    683707    return i==fStateNames.end() || i->second.first.empty() ? s.str() : i->second.first;
     708}
     709
     710// --------------------------------------------------------------------------
     711//
     712//! @param state
     713//!    The state for which should be checked
     714//!
     715//! @returns
     716//!    true if a nam for this state already exists, false otherwise
     717//!
     718bool StateMachineImp::HasState(int state) const
     719{
     720    return fStateNames.find(state) != fStateNames.end();
    684721}
    685722
  • trunk/FACT++/src/StateMachineImp.h

    r14351 r14558  
    2222    {
    2323        kSM_KeepState    =    -42,  ///<
    24         kSM_NotReady   =     -1,  ///< Mainloop not running, state machine stopped
    25         kSM_Ready      =      0,  ///< Mainloop running, state machine in operation
    26         kSM_UserMode   =      1,  ///< First user defined mode (to be used in derived classes' enums)
    27         kSM_Error      =  0x100,  ///< Error states should be between 0x100 and 0xffff
    28         kSM_FatalError = 0xffff,  ///< Fatal error: stop program
     24        kSM_NotAvailable =     -2,  ///< Possible return value for GetStateIndex
     25        kSM_NotReady     =     -1,  ///< Mainloop not running, state machine stopped
     26        kSM_Ready        =      0,  ///< Mainloop running, state machine in operation
     27        kSM_UserMode     =      1,  ///< First user defined mode (to be used in derived classes' enums)
     28        kSM_Error        =  0x100,  ///< Error states should be between 0x100 and 0xffff
     29        kSM_FatalError   = 0xffff,  ///< Fatal error: stop program
    2930    };
    3031
     
    3637    typedef std::map<const int, std::pair<std::string, std::string>> StateNames;
    3738
     39protected:
    3840    /// Human readable names associated with the states
    3941    StateNames fStateNames;
    4042
     43private:
    4144    std::vector<EventImp*> fListOfEvents; /// List of available commands as setup by user
    4245    std::queue<Event*>     fEventQueue;   /// Event queue (fifo) for the received commands
     
    8790    EventImp &AddEvent(const std::string &name, const std::string &fmt, int s1=-1, int s2=-1, int s3=-1, int s4=-1, int s5=-1);
    8891
    89     virtual void AddStateName(const int state, const std::string &name, const std::string &doc="");
     92    virtual bool AddStateName(const int state, const std::string &name, const std::string &doc="");
    9093
    9194    void SetDefaultStateNames();
     
    148151    void PrintListOfStates() const;
    149152
     153
     154    int GetStateIndex(const std::string &name) const;
     155    bool HasState(int index) const;
    150156
    151157    const std::string GetStateName(int state) const;
Note: See TracChangeset for help on using the changeset viewer.