[DEV] signal is better

This commit is contained in:
Edouard DUPIN 2014-08-19 22:57:39 +02:00
parent 749b7a09c0
commit 006ed42f38
2 changed files with 78 additions and 7 deletions

View File

@ -52,6 +52,7 @@ namespace ewol {
bool connect(std::shared_ptr<ewol::Object> _obj, const char* _destId=nullptr, const std::string& _data="" ) {
m_serializedCallerList.push_back(std::make_tuple(_obj, _destId, _data));
return true;
}
bool release(std::shared_ptr<ewol::Object> _obj) {
for (auto it(m_serializedCallerList.begin()) ; it != m_serializedCallerList.end(); ++it) {
@ -88,7 +89,6 @@ namespace ewol {
}
}
*/
bool emit(const std::shared_ptr<ewol::Object>& _source, const T& _data) {
// note : this can not emit on function ....
std::string stringData;
@ -120,6 +120,78 @@ namespace ewol {
}
};
template<> class Signal<void> : public SignalBase {
private:
//std::vector<std::funtion<void(const T&)>> m_callerList;
std::vector<std::tuple<std::weak_ptr<ewol::Object>, const char*, std::string>> m_serializedCallerList;
public:
/**
* @brief Create a parameter with a specific type.
* @param[in] _objectLink reference on the parameter lister.
* @param[in] _name Static name of the parameter.
* @param[in] _defaultValue Default value of the parameter.
* @param[in] _min Minumum value.
* @param[in] _max Maximum value.
* @param[in] _description description of the parameter.
*/
Signal(ewol::object::SignalList& _objectLink,
const std::string& _name,
const std::string& _description = "") :
SignalBase(_objectLink, _name, _description) {
};
/**
* @brief Destructor.
*/
virtual ~Signal() { };
const std::string& getName() {
return m_name;
}
const std::string& getDescription() {
return m_description;
}
bool connect(std::shared_ptr<ewol::Object> _obj, const char* _destId=nullptr, const std::string& _data="" ) {
m_serializedCallerList.push_back(std::make_tuple(_obj, _destId, _data));
return true;
}
bool release(std::shared_ptr<ewol::Object> _obj) {
for (auto it(m_serializedCallerList.begin()) ; it != m_serializedCallerList.end(); ++it) {
if (std::get<0>(it) == _obj) {
m_serializedCallerList.erase(it);
it = m_serializedCallerList.begin();
}
}
}
bool emit(const std::shared_ptr<ewol::Object>& _source) {
// note : this can not emit on function ....
std::string stringData;
for (auto &it : m_serializedCallerList) {
std::shared_ptr<ewol::Object> destObject = std::get<0>(it).lock();
if (destObject == nullptr) {
// TODO : Remove instance ...
EWOL_VERBOSE(" nullptr dest");
continue;
}
const char* eventId = m_name.c_str();
if (std::get<1>(it) != nullptr) {
eventId = std::get<1>(it);
}
if (std::get<2>(it).size() <= 0){
ewol::object::Message tmpMsg(_source, eventId, stringData);
EWOL_VERBOSE("send message " << tmpMsg);
destObject->onReceiveMessage(tmpMsg);
} else {
// set the user requested data ...
ewol::object::Message tmpMsg(_source, eventId, std::get<2>(it));
EWOL_VERBOSE("send message " << tmpMsg);
destObject->onReceiveMessage(tmpMsg);
}
}
}
};
};
};
#endif

View File

@ -31,12 +31,11 @@ namespace ewol {
public:
// Event list of properties
ewol::object::Signal<int> signalPressed;
static const char* const eventPressed;
static const char* const eventDown;
static const char* const eventUp;
static const char* const eventEnter;
static const char* const eventLeave;
static const char* const eventValue;
ewol::object::Signal<void> signalDown;
ewol::object::Signal<void> signalUp;
ewol::object::Signal<void> signalEnter;
ewol::object::Signal<void> signalLeave;
ewol::object::Signal<void> signalValue;
enum buttonLock{
lockNone, //!< normal status of the button
lockWhenPressed, //!< When the state is set in pressed, the status stay in this one