Changeset 14558 for trunk/FACT++/src
- Timestamp:
- 11/05/12 12:02:02 (12 years ago)
- Location:
- trunk/FACT++/src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/StateMachineDim.cc
r14489 r14558 96 96 //! Overwrite StateMachineImp::AddStateName. In addition to storing the 97 97 //! state locally it is also propagated through Dim in the STATE_LIST 98 //! service. 98 //! service. 99 99 //! 100 100 //! @param state … … 107 107 //! A explanatory text describing the state 108 108 //! 109 void StateMachineDim::AddStateName(const int state, const std::string &name, const std::string &doc) 110 { 109 bool 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 111 116 StateMachineImp::AddStateName(state, name, doc); 112 117 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; 120 125 } 121 126 -
trunk/FACT++/src/StateMachineDim.h
r14070 r14558 87 87 int Write(const Time &time, const std::string &txt, int qos=kMessage); 88 88 89 voidAddStateName(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=""); 90 90 }; 91 91 -
trunk/FACT++/src/StateMachineImp.cc
r14124 r14558 659 659 //! A explanatory text describing the state 660 660 //! 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); 661 bool 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 //! 682 int 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; 665 689 } 666 690 … … 682 706 s << state; 683 707 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 //! 718 bool StateMachineImp::HasState(int state) const 719 { 720 return fStateNames.find(state) != fStateNames.end(); 684 721 } 685 722 -
trunk/FACT++/src/StateMachineImp.h
r14351 r14558 22 22 { 23 23 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 29 30 }; 30 31 … … 36 37 typedef std::map<const int, std::pair<std::string, std::string>> StateNames; 37 38 39 protected: 38 40 /// Human readable names associated with the states 39 41 StateNames fStateNames; 40 42 43 private: 41 44 std::vector<EventImp*> fListOfEvents; /// List of available commands as setup by user 42 45 std::queue<Event*> fEventQueue; /// Event queue (fifo) for the received commands … … 87 90 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); 88 91 89 virtual voidAddStateName(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=""); 90 93 91 94 void SetDefaultStateNames(); … … 148 151 void PrintListOfStates() const; 149 152 153 154 int GetStateIndex(const std::string &name) const; 155 bool HasState(int index) const; 150 156 151 157 const std::string GetStateName(int state) const;
Note:
See TracChangeset
for help on using the changeset viewer.