This library is designed to create and run state graphs. It supports hierarchical states and the parallel execution
Diff: StateMachineLib/UserData.h
- Revision:
- 0:f4fdca2c4c67
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/StateMachineLib/UserData.h Tue Oct 03 08:29:22 2017 +0000 @@ -0,0 +1,76 @@ +//////////////////////////////////////////////////////////////////////////////// +// Copyright Rottor SAS 2017 +// All rigths reserved. +// +// File Name : UserData.h +// Authors : Martin Matignon +// +// If you find any bug or if you have any question please contact +// Martin Matignon <martin.matignon@rottor.fr> +// Nicolas Forestier <nicolas.forestier@rottor.fr> +// +//////////////////////////////////////////////////////////////////////////////// + +#ifndef __SM_USER_DATA_H__ +#define __SM_USER_DATA_H__ + +#include "mbed.h" + +#include "MetaData.h" + +class UserData{ + +public: + + struct UserDataItem_t{ + + const char *key; + void *data; + UserDataItem_t *next; + + UserDataItem_t(const char* _key, void* _data); + }; + + UserData(); + + /** Registe template data + * + * @param const char* The data key + * @param T The pointer data + */ + template<typename T> + inline void put(const char* key, T *data){ + UserDataItem_t *newUserData = new UserDataItem_t(key, static_cast<void*>(data)); + this->put(newUserData); + } + + /** Provide template data by key + * + * @param const char* The data key + * @return T The pointer data + */ + template<typename T> + inline T get(const char* key){ + + UserDataItem_t *tmp = m_userDataList; + + while(tmp != NULL) + { + if (strcmp(tmp->key, key) == 0){ + return (T)(tmp->data); + } + tmp = tmp->next; + } + + return NULL; + } + +private: + + void put(UserDataItem_t *ud); + + UserDataItem_t *m_userDataList; + int m_nbUserData; +}; + +#endif /* #ifndef __SM_USER_DATA_H__*/ \ No newline at end of file