diff --git a/examples/events/notifyEventExample/bin/data/.gitkeep b/examples/events/notifyEventExample/bin/data/.gitkeep new file mode 100644 index 00000000000..e69de29bb2d diff --git a/examples/events/notifyEventExample/src/main.cpp b/examples/events/notifyEventExample/src/main.cpp new file mode 100644 index 00000000000..9c9d6da6fef --- /dev/null +++ b/examples/events/notifyEventExample/src/main.cpp @@ -0,0 +1,10 @@ +#include "ofApp.h" +#include "ofMain.h" + +int main() { + + ofGLWindowSettings settings; + auto window = ofCreateWindow(settings); + ofRunApp(window, std::make_shared()); + ofRunMainLoop(); +} diff --git a/examples/events/notifyEventExample/src/ofApp.cpp b/examples/events/notifyEventExample/src/ofApp.cpp new file mode 100644 index 00000000000..c5d31f78318 --- /dev/null +++ b/examples/events/notifyEventExample/src/ofApp.cpp @@ -0,0 +1,52 @@ +#include "ofApp.h" + +void ofApp::update() { + + // you can check the state of a specific ofParameter + // (wrapper around it's own "hidden Event") + // no listeners/callbacks are required + + if (size.didNotify()) { + ofLogNotice("new size") << size; + } + + if (refresh.didNotify()) { + color = ofColor::fromHsb(ofRandom(360), 128, 128); + ofLogNotice("boosch") << color; + } + + if (animate.didNotify()) { // this is the ofAbstractParameter::did_notify() + if (animate != animating) { // sanity check + animating = animate; + if (animating) { + ofLogNotice("stop animation"); + } else { + ofLogNotice("begin animation"); + size = 0; + } + } + } + + if (auto what = params.parameterChangedE().did_notify()) { // this is the Events::did_notify() + // something happended in params, but you don't know what + } +} + +void ofApp::draw() { + ofBackground(0); + if (animating) { + ofSetColor(color); + ofDrawCircle(ofGetWidth() / 2, ofGetHeight() / 2, size); + size = size + 1; + if (size > 100) size -= 100; + } + ofDrawBitmapString(" to toggle automation", 10, 10); + ofDrawBitmapString(" to randomize size", 10, 20); + ofDrawBitmapString(" to change color", 10, 30); +} + +void ofApp::keyPressed(int key) { + if (key == 'a') animate = !animate; + if (key == 'r') size = ofRandom(50, 100); + if (key == 'c') refresh.trigger(); +} diff --git a/examples/events/notifyEventExample/src/ofApp.h b/examples/events/notifyEventExample/src/ofApp.h new file mode 100644 index 00000000000..1931790ee3c --- /dev/null +++ b/examples/events/notifyEventExample/src/ofApp.h @@ -0,0 +1,22 @@ +#pragma once + +#include "ofMain.h" + +// note: this example, inspired by simpleEvents, is kept voluntarily +// as small as possible to give a sense of the bare minimum requirements + +class ofApp : public ofBaseApp { + + ofParameter animate { "animate", false }; + ofParameter refresh { "refresh" }; + ofParameter size { "size", 1.0f, 0.0f, 100.0f }; + ofParameterGroup params { "myCallbacksAndSettings", animate, refresh, size }; + + bool animating { false }; + ofColor color { ofColor::white }; + +public: + void update() override; + void draw() override; + void keyPressed(int key) override; +}; diff --git a/libs/openFrameworks/events/ofEvent.h b/libs/openFrameworks/events/ofEvent.h index 8d3b6af0e84..1500acac0ff 100644 --- a/libs/openFrameworks/events/ofEvent.h +++ b/libs/openFrameworks/events/ofEvent.h @@ -563,33 +563,38 @@ class ofEvent: public of::priv::BaseEvent,Mutex>{ ofEvent::self->remove(*make_function(std::function::function_type>(function), priority)->id); } - inline bool notify(const void* sender, T & param){ - if(ofEvent::self->enabled && !ofEvent::self->functions.empty()){ - std::unique_lock lck(ofEvent::self->mtx); - auto functions_copy = ofEvent::self->functions; - lck.unlock(); - for(auto & f: functions_copy){ - if(f->notify(sender,param)){ - return true; - } - } + /// \brief checks the state of the event + /// \returns true if the Event's state was notified since the last check + bool didNotify() { + if (notified_.load(std::memory_order_relaxed)) { + notified_.store(false, std::memory_order_seq_cst); + return true; + } else { + return false; } - return false; } + std::atomic notified_ { false }; - inline bool notify(T & param){ - if(ofEvent::self->enabled && !ofEvent::self->functions.empty()){ - std::unique_lock lck(ofEvent::self->mtx); - auto functions_copy = ofEvent::self->functions; - lck.unlock(); - for(auto & f: functions_copy){ - if(f->notify(nullptr,param)){ - return true; + inline bool notify(const void* sender, T & param) { + if (ofEvent::self->enabled) { + notified_.store(true, std::memory_order_relaxed); + if (!ofEvent::self->functions.empty()) { + std::unique_lock lck(ofEvent::self->mtx); + auto functions_copy = ofEvent::self->functions; + lck.unlock(); + for (auto & f: functions_copy) { + if (f->notify(sender,param)) { + return true; + } } } } return false; } + + inline bool notify(T & param){ + return this->notify(nullptr, param); + } }; @@ -721,14 +726,29 @@ class ofEvent: public of::priv::BaseEvent::self->remove(*make_function(std::function::function_type>(function),priority)->id); } + /// \brief checks the state of the event + /// \returns true if the Event's state was notified since the last check + bool didNotify() { + if (notified_.load(std::memory_order_relaxed)) { + notified_.store(false, std::memory_order_seq_cst); + return true; + } else { + return false; + } + } + std::atomic notified_; + bool notify(const void* sender){ - if(ofEvent::self->enabled && !ofEvent::self->functions.empty()){ - std::unique_lock lck(ofEvent::self->mtx); - auto functions_copy = ofEvent::self->functions; - lck.unlock(); - for(auto & f: functions_copy){ - if(f->notify(sender)){ - return true; + if(ofEvent::self->enabled) { + notified_.store(true, std::memory_order_relaxed); + if (!ofEvent::self->functions.empty()) { + std::unique_lock lck(ofEvent::self->mtx); + auto functions_copy = ofEvent::self->functions; + lck.unlock(); + for (auto & f: functions_copy) { + if (f->notify(sender)) { + return true; + } } } } @@ -736,17 +756,7 @@ class ofEvent: public of::priv::BaseEvent::self->enabled && !ofEvent::self->functions.empty()){ - std::unique_lock lck(ofEvent::self->mtx); - auto functions_copy = ofEvent::self->functions; - lck.unlock(); - for(auto & f: functions_copy){ - if(f->notify(nullptr)){ - return true; - } - } - } - return false; + return this->notify(nullptr); } }; diff --git a/libs/openFrameworks/types/ofParameter.h b/libs/openFrameworks/types/ofParameter.h index f66ee8c0e19..d5a3c1fcef5 100644 --- a/libs/openFrameworks/types/ofParameter.h +++ b/libs/openFrameworks/types/ofParameter.h @@ -1,5 +1,7 @@ #pragma once +#include + #include "ofEvents.h" // FIXME: crossed references. ofPoint adds ofVec3f which adds ofVec2f and ofVec4f #include "ofPoint.h" @@ -9,23 +11,19 @@ // #include "ofConstants.h" #include "ofColor.h" -#include - -template +template class ofParameter; -template +template class ofReadOnlyParameter; class ofParameterGroup; - - //---------------------------------------------------------------------- /// Base class for ofParameter, ofReadOnlyParameter and ofParameterGroup -class ofAbstractParameter{ +class ofAbstractParameter { public: - virtual ~ofAbstractParameter(){} + virtual ~ofAbstractParameter() { } virtual std::string getName() const = 0; virtual void setName(const std::string & name) = 0; virtual std::string toString() const = 0; @@ -38,75 +36,72 @@ class ofAbstractParameter{ virtual void setParent(ofParameterGroup & _parent) = 0; std::vector getGroupHierarchyNames() const; - template - ofParameter & cast(){ + template + ofParameter & cast() { return static_cast &>(*this); } - template - const ofParameter & cast() const{ + template + const ofParameter & cast() const { return static_cast &>(*this); } - template - ofReadOnlyParameter & castReadOnly(){ + template + ofReadOnlyParameter & castReadOnly() { return static_cast &>(*this); } - template - const ofReadOnlyParameter & castReadOnly() const{ + template + const ofReadOnlyParameter & castReadOnly() const { return static_cast &>(*this); } - template + template bool isOfType() const { return typeid(*this) == typeid(ofParameter); } - + ofParameterGroup & castGroup(); const ofParameterGroup & castGroup() const; - friend std::ostream& operator<<(std::ostream& os, const ofAbstractParameter& p); - friend std::istream& operator>>(std::istream& is, ofAbstractParameter& p); + friend std::ostream & operator<<(std::ostream & os, const ofAbstractParameter & p); + friend std::istream & operator>>(std::istream & is, ofAbstractParameter & p); virtual bool isSerializable() const = 0; virtual bool isReadOnly() const = 0; virtual std::shared_ptr newReference() const = 0; - virtual bool isReferenceTo(const ofAbstractParameter& other) const; + virtual bool isReferenceTo(const ofAbstractParameter & other) const; protected: virtual const ofParameterGroup getFirstParent() const = 0; - virtual void setSerializable(bool serializable)=0; - virtual std::string escape(const std::string& str) const; - virtual const void* getInternalObject() const = 0; + virtual void setSerializable(bool serializable) = 0; + virtual std::string escape(const std::string & str) const; + virtual const void * getInternalObject() const = 0; }; - - - //---------------------------------------------------------------------- /// A collection of parameters with events to notify if a parameter changed /// and serialization facilities -class ofParameterGroup: public ofAbstractParameter { +class ofParameterGroup : public ofAbstractParameter { public: ofParameterGroup(); - template + template ofParameterGroup(const std::string & name) - :obj(std::make_shared()){ + : obj(std::make_shared()) { setName(name); } - template - ofParameterGroup(const std::string & name, Args&... p) - :obj(std::make_shared()){ + template + ofParameterGroup(const std::string & name, Args &... p) + : obj(std::make_shared()) { add(p...); setName(name); } - template - void add(ofAbstractParameter & p, Args&... parameters){ + template + void add(ofAbstractParameter & p, Args &... parameters) { add(p); add(parameters...); } @@ -116,26 +111,25 @@ class ofParameterGroup: public ofAbstractParameter { void remove(ofAbstractParameter & param); void remove(std::size_t index); - void remove(const std::string& name); + void remove(const std::string & name); void clear(); - const ofParameter & getVoid(const std::string& name) const; - const ofParameter & getBool(const std::string& name) const; - const ofParameter & getInt(const std::string& name) const; - const ofParameter & getFloat(const std::string& name) const; - const ofParameter & getChar(const std::string& name) const; - const ofParameter & getString(const std::string& name) const; - const ofParameter & getPoint(const std::string& name) const; - const ofParameter & getVec2f(const std::string& name) const; - const ofParameter & getVec3f(const std::string& name) const; - const ofParameter & getVec4f(const std::string& name) const; - const ofParameter & getColor(const std::string& name) const; - const ofParameter & getShortColor(const std::string& name) const; - const ofParameter & getFloatColor(const std::string& name) const; - const ofParameter & getRectangle(const std::string& name) const; - const ofParameterGroup & getGroup(const std::string& name) const; - + const ofParameter & getVoid(const std::string & name) const; + const ofParameter & getBool(const std::string & name) const; + const ofParameter & getInt(const std::string & name) const; + const ofParameter & getFloat(const std::string & name) const; + const ofParameter & getChar(const std::string & name) const; + const ofParameter & getString(const std::string & name) const; + const ofParameter & getPoint(const std::string & name) const; + const ofParameter & getVec2f(const std::string & name) const; + const ofParameter & getVec3f(const std::string & name) const; + const ofParameter & getVec4f(const std::string & name) const; + const ofParameter & getColor(const std::string & name) const; + const ofParameter & getShortColor(const std::string & name) const; + const ofParameter & getFloatColor(const std::string & name) const; + const ofParameter & getRectangle(const std::string & name) const; + const ofParameterGroup & getGroup(const std::string & name) const; const ofParameter & getVoid(std::size_t pos) const; const ofParameter & getBool(std::size_t pos) const; @@ -153,22 +147,21 @@ class ofParameterGroup: public ofAbstractParameter { const ofParameter & getRectangle(std::size_t pos) const; const ofParameterGroup & getGroup(std::size_t pos) const; - ofParameter & getVoid(const std::string& name); - ofParameter & getBool(const std::string& name); - ofParameter & getInt(const std::string& name); - ofParameter & getFloat(const std::string& name); - ofParameter & getChar(const std::string& name); - ofParameter & getString(const std::string& name); - ofParameter & getPoint(const std::string& name); - ofParameter & getVec2f(const std::string& name); - ofParameter & getVec3f(const std::string& name); - ofParameter & getVec4f(const std::string& name); - ofParameter & getColor(const std::string& name); - ofParameter & getShortColor(const std::string& name); - ofParameter & getFloatColor(const std::string& name); - ofParameter & getRectangle(const std::string& name); - ofParameterGroup & getGroup(const std::string& name); - + ofParameter & getVoid(const std::string & name); + ofParameter & getBool(const std::string & name); + ofParameter & getInt(const std::string & name); + ofParameter & getFloat(const std::string & name); + ofParameter & getChar(const std::string & name); + ofParameter & getString(const std::string & name); + ofParameter & getPoint(const std::string & name); + ofParameter & getVec2f(const std::string & name); + ofParameter & getVec3f(const std::string & name); + ofParameter & getVec4f(const std::string & name); + ofParameter & getColor(const std::string & name); + ofParameter & getShortColor(const std::string & name); + ofParameter & getFloatColor(const std::string & name); + ofParameter & getRectangle(const std::string & name); + ofParameterGroup & getGroup(const std::string & name); ofParameter & getVoid(std::size_t pos); ofParameter & getBool(std::size_t pos); @@ -186,57 +179,57 @@ class ofParameterGroup: public ofAbstractParameter { ofParameter & getRectangle(std::size_t pos); ofParameterGroup & getGroup(std::size_t pos); - const ofAbstractParameter & get(const std::string& name) const; + const ofAbstractParameter & get(const std::string & name) const; const ofAbstractParameter & get(std::size_t pos) const; - const ofAbstractParameter & operator[](const std::string& name) const; + const ofAbstractParameter & operator[](const std::string & name) const; const ofAbstractParameter & operator[](std::size_t pos) const; - ofAbstractParameter & get(const std::string& name); + ofAbstractParameter & get(const std::string & name); ofAbstractParameter & get(std::size_t pos); - ofAbstractParameter & operator[](const std::string& name); + ofAbstractParameter & operator[](const std::string & name); ofAbstractParameter & operator[](std::size_t pos); - template - const ofParameter & get(const std::string& name) const; + template + const ofParameter & get(const std::string & name) const; - template + template const ofParameter & get(std::size_t pos) const; - template - ofParameter & get(const std::string& name); + template + ofParameter & get(const std::string & name); - template + template ofParameter & get(std::size_t pos); - template - const ofReadOnlyParameter & getReadOnly(const std::string& name) const; + template + const ofReadOnlyParameter & getReadOnly(const std::string & name) const; - template + template const ofReadOnlyParameter & getReadOnly(std::size_t pos) const; - template - ofReadOnlyParameter & getReadOnly(const std::string& name); + template + ofReadOnlyParameter & getReadOnly(const std::string & name); - template + template ofReadOnlyParameter & getReadOnly(std::size_t pos); std::size_t size() const; std::string getName(std::size_t position) const; std::string getType(std::size_t position) const; bool getIsReadOnly(int position) const; - int getPosition(const std::string& name) const; + int getPosition(const std::string & name) const; - friend std::ostream& operator<<(std::ostream& os, const ofParameterGroup& group); + friend std::ostream & operator<<(std::ostream & os, const ofParameterGroup & group); std::string getName() const; - void setName(const std::string& name); + void setName(const std::string & name); std::string getEscapedName() const; std::string toString() const; - void fromString(const std::string& name); + void fromString(const std::string & name); - bool contains(const std::string& name) const; + bool contains(const std::string & name) const; ofAbstractParameter & back(); ofAbstractParameter & front(); @@ -254,28 +247,28 @@ class ofParameterGroup: public ofAbstractParameter { ofEvent & parameterChangedE(); - std::vector >::iterator begin(); - std::vector >::iterator end(); - std::vector >::const_iterator begin() const; - std::vector >::const_iterator end() const; - std::vector >::reverse_iterator rbegin(); - std::vector >::reverse_iterator rend(); - std::vector >::const_reverse_iterator rbegin() const; - std::vector >::const_reverse_iterator rend() const; + std::vector>::iterator begin(); + std::vector>::iterator end(); + std::vector>::const_iterator begin() const; + std::vector>::const_iterator end() const; + std::vector>::reverse_iterator rbegin(); + std::vector>::reverse_iterator rend(); + std::vector>::const_reverse_iterator rbegin() const; + std::vector>::const_reverse_iterator rend() const; protected: - const void* getInternalObject() const; + const void * getInternalObject() const; private: - class Value{ + class Value { public: Value() - :serializable(true){} + : serializable(true) { } void notifyParameterChanged(ofAbstractParameter & param); - std::map parametersIndex; - std::vector > parameters; + std::map parametersIndex; + std::vector> parameters; std::string name; bool serializable; std::vector> parents; @@ -283,208 +276,205 @@ class ofParameterGroup: public ofAbstractParameter { }; std::shared_ptr obj; ofParameterGroup(std::shared_ptr obj) - :obj(obj){} + : obj(obj) { } - template + template friend class ofParameter; - template + template friend class ofReadOnlyParameter; const ofParameterGroup getFirstParent() const; }; -template -const ofParameter & ofParameterGroup::get(const std::string& name) const{ - return static_cast& >(get(name)); +template +const ofParameter & ofParameterGroup::get(const std::string & name) const { + return static_cast &>(get(name)); } -template -const ofParameter & ofParameterGroup::get(std::size_t pos) const{ - return static_cast& >(get(pos)); +template +const ofParameter & ofParameterGroup::get(std::size_t pos) const { + return static_cast &>(get(pos)); } -template -ofParameter & ofParameterGroup::get(const std::string& name){ - return static_cast& >(get(name)); +template +ofParameter & ofParameterGroup::get(const std::string & name) { + return static_cast &>(get(name)); } -template -ofParameter & ofParameterGroup::get(std::size_t pos){ - return static_cast& >(get(pos)); +template +ofParameter & ofParameterGroup::get(std::size_t pos) { + return static_cast &>(get(pos)); } - -template -const ofReadOnlyParameter & ofParameterGroup::getReadOnly(const std::string& name) const{ - return static_cast& >(get(name)); +template +const ofReadOnlyParameter & ofParameterGroup::getReadOnly(const std::string & name) const { + return static_cast &>(get(name)); } -template -const ofReadOnlyParameter & ofParameterGroup::getReadOnly(std::size_t pos) const{ - return static_cast& >(get(pos)); +template +const ofReadOnlyParameter & ofParameterGroup::getReadOnly(std::size_t pos) const { + return static_cast &>(get(pos)); } -template -ofReadOnlyParameter & ofParameterGroup::getReadOnly(const std::string& name){ - return static_cast& >(get(name)); +template +ofReadOnlyParameter & ofParameterGroup::getReadOnly(const std::string & name) { + return static_cast &>(get(name)); } -template -ofReadOnlyParameter & ofParameterGroup::getReadOnly(std::size_t pos){ - return static_cast& >(get(pos)); +template +ofReadOnlyParameter & ofParameterGroup::getReadOnly(std::size_t pos) { + return static_cast &>(get(pos)); } - /*! \cond PRIVATE */ -namespace of{ -namespace priv{ - //---------------------------------------------------------------------- - // Mechanism to provide min and max default values for types where it makes sense - template - struct TypeInfo_ { - }; +namespace of { +namespace priv { +//---------------------------------------------------------------------- +// Mechanism to provide min and max default values for types where it makes sense +template +struct TypeInfo_ { +}; - // Types with numeric_limits resolve to this template specialization: - template - struct TypeInfo_ { - static T min() { return std::numeric_limits::lowest(); } - static T max() { return std::numeric_limits::max(); } - }; +// Types with numeric_limits resolve to this template specialization: +template +struct TypeInfo_ { + static T min() { return std::numeric_limits::lowest(); } + static T max() { return std::numeric_limits::max(); } +}; - template<> - struct TypeInfo_ { - static float min() { return 0; } - static float max() { return 1; } - }; +template <> +struct TypeInfo_ { + static float min() { return 0; } + static float max() { return 1; } +}; - template<> - struct TypeInfo_ { - static float min() { return 0; } - static float max() { return 1; } - }; +template <> +struct TypeInfo_ { + static float min() { return 0; } + static float max() { return 1; } +}; - // Types without numeric_limits resolve to this template specialization: - template - struct TypeInfo_ { - static T min() { return T(); } - static T max() { return T(); } - }; +// Types without numeric_limits resolve to this template specialization: +template +struct TypeInfo_ { + static T min() { return T(); } + static T max() { return T(); } +}; - template - struct TypeInfo : public of::priv::TypeInfo_::is_specialized> { - }; +template +struct TypeInfo : public of::priv::TypeInfo_::is_specialized> { +}; - // Here we provide some of our own specializations: - template<> - struct TypeInfo { - static ofVec2f min() { return ofVec2f(0); } - static ofVec2f max() { return ofVec2f(1); } - }; +// Here we provide some of our own specializations: +template <> +struct TypeInfo { + static ofVec2f min() { return ofVec2f(0); } + static ofVec2f max() { return ofVec2f(1); } +}; - template<> - struct TypeInfo { - static glm::vec2 min() { return glm::vec2(0); } - static glm::vec2 max() { return glm::vec2(1); } - }; +template <> +struct TypeInfo { + static glm::vec2 min() { return glm::vec2(0); } + static glm::vec2 max() { return glm::vec2(1); } +}; - template<> - struct TypeInfo { - static ofVec3f min() { return ofVec3f(0); } - static ofVec3f max() { return ofVec3f(1); } - }; +template <> +struct TypeInfo { + static ofVec3f min() { return ofVec3f(0); } + static ofVec3f max() { return ofVec3f(1); } +}; - template<> - struct TypeInfo { - static glm::vec3 min() { return glm::vec3(0); } - static glm::vec3 max() { return glm::vec3(1); } - }; +template <> +struct TypeInfo { + static glm::vec3 min() { return glm::vec3(0); } + static glm::vec3 max() { return glm::vec3(1); } +}; - template<> - struct TypeInfo { - static ofVec4f min() { return ofVec4f(0); } - static ofVec4f max() { return ofVec4f(1); } - }; +template <> +struct TypeInfo { + static ofVec4f min() { return ofVec4f(0); } + static ofVec4f max() { return ofVec4f(1); } +}; - template<> - struct TypeInfo { - static glm::vec4 min() { return glm::vec4(0); } - static glm::vec4 max() { return glm::vec4(1); } - }; +template <> +struct TypeInfo { + static glm::vec4 min() { return glm::vec4(0); } + static glm::vec4 max() { return glm::vec4(1); } +}; - template - struct TypeInfo > { - static ofColor_ min() { return ofColor_(0,0); } - static ofColor_ max() { return ofColor_(ofColor_::limit(),ofColor_::limit()); } - }; - template<> - struct TypeInfo { +template +struct TypeInfo> { + static ofColor_ min() { return ofColor_(0, 0); } + static ofColor_ max() { return ofColor_(ofColor_::limit(), ofColor_::limit()); } +}; +template <> +struct TypeInfo { //Not really sure what would make sense here!!! - static ofRectangle min() { return ofRectangle(0,0,0,0); } - static ofRectangle max() { return ofRectangle(0,0,1,1); } - }; - + static ofRectangle min() { return ofRectangle(0, 0, 0, 0); } + static ofRectangle max() { return ofRectangle(0, 0, 1, 1); } +}; - // detection of stream operators - typedef char yes; - typedef char (&no)[2]; +// detection of stream operators +typedef char yes; +typedef char (&no)[2]; - struct anyx { template anyx(const T &); }; +struct anyx { + template + anyx(const T &); +}; - no operator << (const anyx &, const anyx &); - no operator >> (const anyx &, const anyx &); +no operator<<(const anyx &, const anyx &); +no operator>>(const anyx &, const anyx &); - - template yes check_op(T const&); - no check_op(no); +template +yes check_op(T const &); +no check_op(no); - template - struct has_loading_support { - static std::istream & stream; - static T & x; - static constexpr bool value = sizeof(check_op(stream >> x)) == sizeof(yes); - }; - - template - struct has_saving_support { - static std::ostream & stream; - static T & x; - static constexpr bool value = sizeof(check_op(stream << x)) == sizeof(yes); - }; +template +struct has_loading_support { + static std::istream & stream; + static T & x; + static constexpr bool value = sizeof(check_op(stream >> x)) == sizeof(yes); +}; - template - struct has_stream_operators { - static constexpr bool can_load = has_loading_support::value; - static constexpr bool can_save = has_saving_support::value; - static constexpr bool value = can_load && can_save; - }; +template +struct has_saving_support { + static std::ostream & stream; + static T & x; + static constexpr bool value = sizeof(check_op(stream << x)) == sizeof(yes); +}; - template - typename std::enable_if::value, std::string>::type toStringImpl(const ParameterType & value){ - return ofToString(value); - } +template +struct has_stream_operators { + static constexpr bool can_load = has_loading_support::value; + static constexpr bool can_save = has_saving_support::value; + static constexpr bool value = can_load && can_save; +}; - template - typename std::enable_if::value, std::string>::type toStringImpl(const ParameterType &){ - throw std::exception(); - } +template +typename std::enable_if::value, std::string>::type toStringImpl(const ParameterType & value) { + return ofToString(value); +} - template - typename std::enable_if::value, ParameterType>::type fromStringImpl(const std::string & str){ - return ofFromString(str); - } +template +typename std::enable_if::value, std::string>::type toStringImpl(const ParameterType &) { + throw std::exception(); +} - template - typename std::enable_if::value, ParameterType>::type fromStringImpl(const std::string &){ - throw std::exception(); +template +typename std::enable_if::value, ParameterType>::type fromStringImpl(const std::string & str) { + return ofFromString(str); +} - } +template +typename std::enable_if::value, ParameterType>::type fromStringImpl(const std::string &) { + throw std::exception(); +} } } /*! \endcond */ - - /// \brief ofParameter holds a value and notifies its listeners when it changes. /// /// ofParameter can be used as the value itself. For example an `ofParameter` @@ -495,44 +485,50 @@ namespace priv{ /// e.g. `myObject->myMethod();`. /// /// \tparam ParameterType The data wrapped by the ofParameter. -template -class ofParameter: public ofAbstractParameter{ +template +class ofParameter : public ofAbstractParameter { public: ofParameter(); ofParameter(const ofParameter & v); ofParameter(const ParameterType & v); - ofParameter(const std::string& name, const ParameterType & v); - ofParameter(const std::string& name, const ParameterType & v, const ParameterType & min, const ParameterType & max); + ofParameter(const std::string & name, const ParameterType & v); + ofParameter(const std::string & name, const ParameterType & v, const ParameterType & min, const ParameterType & max); const ParameterType & get() const; const ParameterType * operator->() const; - operator const ParameterType & () const; + operator const ParameterType &() const; void setName(const std::string & name); std::string getName() const; ParameterType getMin() const; - ParameterType getMax() const; + ParameterType getMax() const; + + ParameterType getInit() const; + void reInit(); - ParameterType getInit() const; - void reInit(); + /// \brief queries the parameter's event about its notification state + /// \returns true if the event was notified since last check + auto didNotify() { + return obj->changedE.didNotify(); + } std::string toString() const; void fromString(const std::string & name); - template - void addListener(ListenerClass * listener, ListenerMethod method, int prio=OF_EVENT_ORDER_AFTER_APP){ - ofAddListener(obj->changedE,listener,method,prio); + template + void addListener(ListenerClass * listener, ListenerMethod method, int prio = OF_EVENT_ORDER_AFTER_APP) { + ofAddListener(obj->changedE, listener, method, prio); } - template - void removeListener(ListenerClass * listener, ListenerMethod method, int prio=OF_EVENT_ORDER_AFTER_APP){ - ofRemoveListener(obj->changedE,listener,method,prio); + template + void removeListener(ListenerClass * listener, ListenerMethod method, int prio = OF_EVENT_ORDER_AFTER_APP) { + ofRemoveListener(obj->changedE, listener, method, prio); } - template - std::unique_ptr newListener(Args...args) { + template + std::unique_ptr newListener(Args... args) { return obj->changedE.newListener(args...); } @@ -553,94 +549,92 @@ class ofParameter: public ofAbstractParameter{ ParameterType operator--(int v); ofParameter & operator--(); - template + template ofParameter & operator+=(const OtherType & v); - template + template ofParameter & operator-=(const OtherType & v); - template + template ofParameter & operator*=(const OtherType & v); - template + template ofParameter & operator/=(const OtherType & v); - template + template ofParameter & operator%=(const OtherType & v); - template + template ofParameter & operator&=(const OtherType & v); - template + template ofParameter & operator|=(const OtherType & v); - template + template ofParameter & operator^=(const OtherType & v); - template + template ofParameter & operator<<=(const OtherType & v); - template + template ofParameter & operator>>=(const OtherType & v); - ofParameter & set(const ParameterType & v); - ofParameter & set(const std::string& name, const ParameterType & v); - ofParameter & set(const std::string& name, const ParameterType & v, const ParameterType & min, const ParameterType & max); + ofParameter & set(const std::string & name, const ParameterType & v); + ofParameter & set(const std::string & name, const ParameterType & v, const ParameterType & min, const ParameterType & max); ofParameter & setWithoutEventNotifications(const ParameterType & v); void setMin(const ParameterType & min); - void setMax(const ParameterType & max); - void setInit(const ParameterType & init); + void setMax(const ParameterType & max); + void setInit(const ParameterType & init); void setSerializable(bool serializable); std::shared_ptr newReference() const; void setParent(ofParameterGroup & _parent); - const ofParameterGroup getFirstParent() const{ - obj->parents.erase(std::remove_if(obj->parents.begin(),obj->parents.end(), - [](std::weak_ptr p){return p.lock()==nullptr;}), - obj->parents.end()); - if(!obj->parents.empty()){ + const ofParameterGroup getFirstParent() const { + obj->parents.erase(std::remove_if(obj->parents.begin(), obj->parents.end(), + [](std::weak_ptr p) { return p.lock() == nullptr; }), + obj->parents.end()); + if (!obj->parents.empty()) { return obj->parents.front().lock(); - }else{ + } else { return std::shared_ptr(nullptr); } } size_t getNumListeners() const; - const void* getInternalObject() const; + const void * getInternalObject() const; protected: - private: - class Value{ + class Value { public: Value() - :init(of::priv::TypeInfo::min()) - ,min(of::priv::TypeInfo::min()) - ,max(of::priv::TypeInfo::max()) - ,bInNotify(false) - ,serializable(true){} + : init(of::priv::TypeInfo::min()) + , min(of::priv::TypeInfo::min()) + , max(of::priv::TypeInfo::max()) + , bInNotify(false) + , serializable(true) { } Value(ParameterType v) - :init(v) - ,value(v) - ,min(of::priv::TypeInfo::min()) - ,max(of::priv::TypeInfo::max()) - ,bInNotify(false) - ,serializable(true){} + : init(v) + , value(v) + , min(of::priv::TypeInfo::min()) + , max(of::priv::TypeInfo::max()) + , bInNotify(false) + , serializable(true) { } Value(std::string name, ParameterType v) - :name(name) - ,init(v) - ,value(v) - ,min(of::priv::TypeInfo::min()) - ,max(of::priv::TypeInfo::max()) - ,bInNotify(false) - ,serializable(true){} + : name(name) + , init(v) + , value(v) + , min(of::priv::TypeInfo::min()) + , max(of::priv::TypeInfo::max()) + , bInNotify(false) + , serializable(true) { } Value(std::string name, ParameterType v, ParameterType min, ParameterType max) - :name(name) - ,init(v) - ,value(v) - ,min(min) - ,max(max) - ,bInNotify(false) - ,serializable(true){} + : name(name) + , init(v) + , value(v) + , min(min) + , max(max) + , bInNotify(false) + , serializable(true) { } std::string name; ParameterType init, value, min, max; @@ -656,97 +650,92 @@ class ofParameter: public ofAbstractParameter{ void eventsSetValue(const ParameterType & v); void noEventsSetValue(const ParameterType & v); - template + template friend class ofReadOnlyParameter; }; - -template +template ofParameter::ofParameter() -:obj(std::make_shared()) -,setMethod(std::bind(&ofParameter::eventsSetValue, this, std::placeholders::_1)){} + : obj(std::make_shared()) + , setMethod(std::bind(&ofParameter::eventsSetValue, this, std::placeholders::_1)) { } -template +template ofParameter::ofParameter(const ofParameter & v) -:obj(v.obj) -,setMethod(std::bind(&ofParameter::eventsSetValue, this, std::placeholders::_1)) {} + : obj(v.obj) + , setMethod(std::bind(&ofParameter::eventsSetValue, this, std::placeholders::_1)) { } -template +template ofParameter::ofParameter(const ParameterType & v) -:obj(std::make_shared(v)) -,setMethod(std::bind(&ofParameter::eventsSetValue, this, std::placeholders::_1)) {} - -template -ofParameter::ofParameter(const std::string& name, const ParameterType & v) -:obj(std::make_shared(name, v)) -,setMethod(std::bind(&ofParameter::eventsSetValue, this, std::placeholders::_1)){} + : obj(std::make_shared(v)) + , setMethod(std::bind(&ofParameter::eventsSetValue, this, std::placeholders::_1)) { } -template -ofParameter::ofParameter(const std::string& name, const ParameterType & v, const ParameterType & min, const ParameterType & max) -:obj(std::make_shared(name, v, min, max)) -,setMethod(std::bind(&ofParameter::eventsSetValue, this, std::placeholders::_1)){} +template +ofParameter::ofParameter(const std::string & name, const ParameterType & v) + : obj(std::make_shared(name, v)) + , setMethod(std::bind(&ofParameter::eventsSetValue, this, std::placeholders::_1)) { } +template +ofParameter::ofParameter(const std::string & name, const ParameterType & v, const ParameterType & min, const ParameterType & max) + : obj(std::make_shared(name, v, min, max)) + , setMethod(std::bind(&ofParameter::eventsSetValue, this, std::placeholders::_1)) { } -template -inline ofParameter & ofParameter::operator=(const ofParameter & v){ +template +inline ofParameter & ofParameter::operator=(const ofParameter & v) { set(v); return *this; } -template -inline const ParameterType & ofParameter::operator=(const ParameterType & v){ +template +inline const ParameterType & ofParameter::operator=(const ParameterType & v) { set(v); return obj->value; } -template -inline ofParameter & ofParameter::set(const ParameterType & v){ +template +inline ofParameter & ofParameter::set(const ParameterType & v) { setMethod(v); return *this; } -template -ofParameter & ofParameter::set(const std::string& name, const ParameterType & value, const ParameterType & min, const ParameterType & max){ +template +ofParameter & ofParameter::set(const std::string & name, const ParameterType & value, const ParameterType & min, const ParameterType & max) { setName(name); set(value); setMin(min); setMax(max); - setInit(value); + setInit(value); return *this; } -template -ofParameter & ofParameter::set(const std::string& name, const ParameterType & value){ +template +ofParameter & ofParameter::set(const std::string & name, const ParameterType & value) { setName(name); set(value); return *this; } -template -inline ofParameter & ofParameter::setWithoutEventNotifications(const ParameterType & v){ +template +inline ofParameter & ofParameter::setWithoutEventNotifications(const ParameterType & v) { noEventsSetValue(v); return *this; } -template -inline const ParameterType & ofParameter::get() const{ +template +inline const ParameterType & ofParameter::get() const { return obj->value; } -template -inline const ParameterType * ofParameter::operator->() const{ +template +inline const ParameterType * ofParameter::operator->() const { return &obj->value; } -template -inline void ofParameter::eventsSetValue(const ParameterType & v){ +template +inline void ofParameter::eventsSetValue(const ParameterType & v) { // If the object is notifying its parents, just set the value without triggering an event. - if(obj->bInNotify) - { + if (obj->bInNotify) { noEventsSetValue(v); - } - else - { + } else { // Mark the object as in its notification loop. obj->bInNotify = true; @@ -754,24 +743,23 @@ inline void ofParameter::eventsSetValue(const ParameterType & v){ obj->value = v; // Notify any local subscribers. - ofNotifyEvent(obj->changedE,obj->value,this); + ofNotifyEvent(obj->changedE, obj->value, this); // Notify all parents, if there are any. - if(!obj->parents.empty()) - { + if (!obj->parents.empty()) { // Erase each invalid parent obj->parents.erase(std::remove_if(obj->parents.begin(), - obj->parents.end(), - [](const std::weak_ptr & p){ return p.expired(); }), - obj->parents.end()); + obj->parents.end(), + [](const std::weak_ptr & p) { return p.expired(); }), + obj->parents.end()); // notify all leftover (valid) parents of this object's changed value. // this can't happen in the same iterator as above, because a notified listener // might perform similar cleanups that would corrupt our iterator // (which appens for example if the listener calls getFirstParent on us) - for(auto & parent: obj->parents){ + for (auto & parent : obj->parents) { auto p = parent.lock(); - if(p){ + if (p) { p->notifyParameterChanged(*this); } } @@ -780,253 +768,252 @@ inline void ofParameter::eventsSetValue(const ParameterType & v){ } } -template -inline void ofParameter::noEventsSetValue(const ParameterType & v){ +template +inline void ofParameter::noEventsSetValue(const ParameterType & v) { obj->value = v; } - -template -void ofParameter::setSerializable(bool serializable){ +template +void ofParameter::setSerializable(bool serializable) { obj->serializable = serializable; } -template -bool ofParameter::isSerializable() const{ +template +bool ofParameter::isSerializable() const { return of::priv::has_stream_operators::value && obj->serializable; } -template -bool ofParameter::isReadOnly() const{ +template +bool ofParameter::isReadOnly() const { return false; } -template -std::string ofParameter::valueType() const{ +template +std::string ofParameter::valueType() const { return typeid(ParameterType).name(); } -template -void ofParameter::setMin(const ParameterType & min){ +template +void ofParameter::setMin(const ParameterType & min) { obj->min = min; } -template +template ParameterType ofParameter::getMin() const { return obj->min; } -template -void ofParameter::setMax(const ParameterType & max){ - obj->max = max; +template +void ofParameter::setMax(const ParameterType & max) { + obj->max = max; } -template +template ParameterType ofParameter::getMax() const { - return obj->max; + return obj->max; } -template -void ofParameter::setInit(const ParameterType & init){ - obj->init = init; +template +void ofParameter::setInit(const ParameterType & init) { + obj->init = init; } -template +template ParameterType ofParameter::getInit() const { - return obj->init; + return obj->init; } -template +template void ofParameter::reInit() { - setMethod(obj->init); + setMethod(obj->init); } -template -inline ofParameter::operator const ParameterType & () const{ +template +inline ofParameter::operator const ParameterType &() const { return obj->value; } -template -void ofParameter::setName(const std::string & name){ +template +void ofParameter::setName(const std::string & name) { obj->name = name; } -template -std::string ofParameter::getName() const{ +template +std::string ofParameter::getName() const { return obj->name; } -template -inline std::string ofParameter::toString() const{ - try{ +template +inline std::string ofParameter::toString() const { + try { return of::priv::toStringImpl(obj->value); - }catch(...){ + } catch (...) { ofLogError("ofParameter") << "Trying to serialize non-serializable parameter"; return ""; } } -template -inline void ofParameter::fromString(const std::string & str){ - try{ +template +inline void ofParameter::fromString(const std::string & str) { + try { set(of::priv::fromStringImpl(str)); - }catch(...){ + } catch (...) { ofLogError("ofParameter") << "Trying to de-serialize non-serializable parameter"; } } -template -void ofParameter::enableEvents(){ +template +void ofParameter::enableEvents() { setMethod = std::bind(&ofParameter::eventsSetValue, this, std::placeholders::_1); } -template -void ofParameter::disableEvents(){ +template +void ofParameter::disableEvents() { setMethod = std::bind(&ofParameter::noEventsSetValue, this, std::placeholders::_1); } -template -inline ParameterType ofParameter::operator++(int){ +template +inline ParameterType ofParameter::operator++(int) { ParameterType r = obj->value; obj->value++; set(obj->value); return r; } -template -inline ofParameter & ofParameter::operator++(){ +template +inline ofParameter & ofParameter::operator++() { ++obj->value; set(obj->value); return *this; } -template -inline ParameterType ofParameter::operator--(int){ +template +inline ParameterType ofParameter::operator--(int) { ParameterType r = obj->value; obj->value--; set(obj->value); return r; } -template -inline ofParameter & ofParameter::operator--(){ +template +inline ofParameter & ofParameter::operator--() { --obj->value; set(obj->value); return *this; } -template -template -inline ofParameter & ofParameter::operator+=(const OtherType & v){ - obj->value+=v; +template +template +inline ofParameter & ofParameter::operator+=(const OtherType & v) { + obj->value += v; set(obj->value); return *this; } -template -template -inline ofParameter & ofParameter::operator-=(const OtherType & v){ - obj->value-=v; +template +template +inline ofParameter & ofParameter::operator-=(const OtherType & v) { + obj->value -= v; set(obj->value); return *this; } -template -template -inline ofParameter & ofParameter::operator*=(const OtherType & v){ - obj->value*=v; +template +template +inline ofParameter & ofParameter::operator*=(const OtherType & v) { + obj->value *= v; set(obj->value); return *this; } -template -template -inline ofParameter & ofParameter::operator/=(const OtherType & v){ - obj->value/=v; +template +template +inline ofParameter & ofParameter::operator/=(const OtherType & v) { + obj->value /= v; set(obj->value); return *this; } -template -template -inline ofParameter & ofParameter::operator%=(const OtherType & v){ - obj->value%=v; +template +template +inline ofParameter & ofParameter::operator%=(const OtherType & v) { + obj->value %= v; set(obj->value); return *this; } -template -template -inline ofParameter & ofParameter::operator&=(const OtherType & v){ - obj->value&=v; +template +template +inline ofParameter & ofParameter::operator&=(const OtherType & v) { + obj->value &= v; set(obj->value); return *this; } -template -template -ofParameter & ofParameter::operator|=(const OtherType & v){ - obj->value|=v; +template +template +ofParameter & ofParameter::operator|=(const OtherType & v) { + obj->value |= v; set(obj->value); return *this; } -template -template -inline ofParameter & ofParameter::operator^=(const OtherType & v){ - obj->value^=v; +template +template +inline ofParameter & ofParameter::operator^=(const OtherType & v) { + obj->value ^= v; set(obj->value); return *this; } -template -template -inline ofParameter & ofParameter::operator<<=(const OtherType & v){ - obj->value<<=v; +template +template +inline ofParameter & ofParameter::operator<<=(const OtherType & v) { + obj->value <<= v; set(obj->value); return *this; } -template -template -inline ofParameter & ofParameter::operator>>=(const OtherType & v){ - obj->value>>=v; +template +template +inline ofParameter & ofParameter::operator>>=(const OtherType & v) { + obj->value >>= v; set(obj->value); return *this; } -template -void ofParameter::makeReferenceTo(ofParameter & mom){ +template +void ofParameter::makeReferenceTo(ofParameter & mom) { obj = mom.obj; } -template -std::shared_ptr ofParameter::newReference() const{ +template +std::shared_ptr ofParameter::newReference() const { return std::make_shared>(*this); } -template -void ofParameter::setParent(ofParameterGroup & parent){ +template +void ofParameter::setParent(ofParameterGroup & parent) { obj->parents.emplace_back(parent.obj); } -template -size_t ofParameter::getNumListeners() const{ +template +size_t ofParameter::getNumListeners() const { return obj->changedE.size(); } -template -const void* ofParameter::getInternalObject() const{ +template +const void * ofParameter::getInternalObject() const { return obj.get(); } -template<> -class ofParameter: public ofAbstractParameter{ +template <> +class ofParameter : public ofAbstractParameter { public: ofParameter(); - ofParameter(const std::string& name); + ofParameter(const std::string & name); - ofParameter& set(const std::string & name); + ofParameter & set(const std::string & name); void setName(const std::string & name); std::string getName() const; @@ -1034,21 +1021,27 @@ class ofParameter: public ofAbstractParameter{ std::string toString() const; void fromString(const std::string & name); - template - void addListener(ListenerClass * listener, ListenerMethod method, int prio=OF_EVENT_ORDER_AFTER_APP){ - ofAddListener(obj->changedE,listener,method,prio); + template + void addListener(ListenerClass * listener, ListenerMethod method, int prio = OF_EVENT_ORDER_AFTER_APP) { + ofAddListener(obj->changedE, listener, method, prio); } - template - void removeListener(ListenerClass * listener, ListenerMethod method, int prio=OF_EVENT_ORDER_AFTER_APP){ - ofRemoveListener(obj->changedE,listener,method,prio); + template + void removeListener(ListenerClass * listener, ListenerMethod method, int prio = OF_EVENT_ORDER_AFTER_APP) { + ofRemoveListener(obj->changedE, listener, method, prio); } - template - std::unique_ptr newListener(Args...args) { + template + std::unique_ptr newListener(Args... args) { return obj->changedE.newListener(args...); } + /// \brief queries the parameter's event about its notification state + /// \returns true if the event was notified since last check + auto didNotify() { + return obj->changedE.didNotify(); + } + void trigger(); void trigger(const void * sender); @@ -1065,30 +1058,30 @@ class ofParameter: public ofAbstractParameter{ void setParent(ofParameterGroup & _parent); - const ofParameterGroup getFirstParent() const{ - auto first = std::find_if(obj->parents.begin(),obj->parents.end(),[](std::weak_ptr p){return p.lock()!=nullptr;}); - if(first!=obj->parents.end()){ + const ofParameterGroup getFirstParent() const { + auto first = std::find_if(obj->parents.begin(), obj->parents.end(), [](std::weak_ptr p) { return p.lock() != nullptr; }); + if (first != obj->parents.end()) { return first->lock(); - }else{ + } else { return std::shared_ptr(nullptr); } } size_t getNumListeners() const; - const void* getInternalObject() const{ + const void * getInternalObject() const { return obj.get(); } -protected: +protected: private: - class Value{ + class Value { public: Value() - :serializable(false){} + : serializable(false) { } Value(std::string name) - :name(name) - ,serializable(false){} + : name(name) + , serializable(false) { } std::string name; ofEvent changedE; @@ -1098,8 +1091,6 @@ class ofParameter: public ofAbstractParameter{ std::shared_ptr obj; }; - - /// \brief ofReadOnlyParameter holds a value and notifies its listeners when it changes. /// /// ofReadOnlyParameter is a "read only" version of `ofPareameter`. "Friend" @@ -1110,19 +1101,19 @@ class ofParameter: public ofAbstractParameter{ /// \sa ofParameter /// \tparam ParameterType The data wrapped by the ofParameter. /// \tparam Friend The type of the "friend" class with write access. -template -class ofReadOnlyParameter: public ofAbstractParameter{ +template +class ofReadOnlyParameter : public ofAbstractParameter { public: ofReadOnlyParameter(); -// ofReadOnlyParameter(ofParameter & p); -// ofReadOnlyParameter(ofReadOnlyParameter & p); + // ofReadOnlyParameter(ofParameter & p); + // ofReadOnlyParameter(ofReadOnlyParameter & p); ofReadOnlyParameter(const ParameterType & v); - ofReadOnlyParameter(const std::string& name, const ParameterType & v); - ofReadOnlyParameter(const std::string& name, const ParameterType & v, const ParameterType & min, const ParameterType & max); + ofReadOnlyParameter(const std::string & name, const ParameterType & v); + ofReadOnlyParameter(const std::string & name, const ParameterType & v, const ParameterType & min, const ParameterType & max); const ParameterType & get() const; const ParameterType * operator->() const; - operator const ParameterType & () const; + operator const ParameterType &() const; std::string getName() const; @@ -1132,16 +1123,16 @@ class ofReadOnlyParameter: public ofAbstractParameter{ std::string toString() const; - template - void addListener(ListenerClass * listener, ListenerMethod method, int prio=OF_EVENT_ORDER_AFTER_APP); + template + void addListener(ListenerClass * listener, ListenerMethod method, int prio = OF_EVENT_ORDER_AFTER_APP); - template - void removeListener(ListenerClass * listener, ListenerMethod method, int prio=OF_EVENT_ORDER_AFTER_APP); + template + void removeListener(ListenerClass * listener, ListenerMethod method, int prio = OF_EVENT_ORDER_AFTER_APP); std::shared_ptr newReference() const; - template - std::unique_ptr newListener(Args...args); + template + std::unique_ptr newListener(Args... args); bool isSerializable() const; bool isReadOnly() const; @@ -1153,76 +1144,74 @@ class ofReadOnlyParameter: public ofAbstractParameter{ void disableEvents(); void setSerializable(bool s); - template - void makeReferenceTo(ofReadOnlyParameter mom); + template + void makeReferenceTo(ofReadOnlyParameter mom); void makeReferenceTo(ofParameter mom); - ofReadOnlyParameter & operator=(const ofReadOnlyParameter& v); - ofReadOnlyParameter & operator=(const ofParameter& v); + ofReadOnlyParameter & operator=(const ofReadOnlyParameter & v); + ofReadOnlyParameter & operator=(const ofParameter & v); const ParameterType & operator=(const ParameterType & v); ParameterType operator++(int v); - ofReadOnlyParameter& operator++(); + ofReadOnlyParameter & operator++(); ParameterType operator--(int v); - ofReadOnlyParameter& operator--(); - - template - ofReadOnlyParameter& operator+=(const OtherType & v); - template - ofReadOnlyParameter& operator-=(const OtherType & v); - template - ofReadOnlyParameter& operator*=(const OtherType & v); - template - ofReadOnlyParameter& operator/=(const OtherType & v); - template - ofReadOnlyParameter& operator%=(const OtherType & v); - template - ofReadOnlyParameter& operator&=(const OtherType & v); - template - ofReadOnlyParameter& operator|=(const OtherType & v); - template - ofReadOnlyParameter& operator^=(const OtherType & v); - template - ofReadOnlyParameter& operator<<=(const OtherType & v); - template - ofReadOnlyParameter& operator>>=(const OtherType & v); - - - ofReadOnlyParameter& set(const ParameterType & v); - - ofReadOnlyParameter& set(const std::string& name, const ParameterType & value); - ofReadOnlyParameter& set(const std::string& name, const ParameterType & value, const ParameterType & min, const ParameterType & max); + ofReadOnlyParameter & operator--(); + + template + ofReadOnlyParameter & operator+=(const OtherType & v); + template + ofReadOnlyParameter & operator-=(const OtherType & v); + template + ofReadOnlyParameter & operator*=(const OtherType & v); + template + ofReadOnlyParameter & operator/=(const OtherType & v); + template + ofReadOnlyParameter & operator%=(const OtherType & v); + template + ofReadOnlyParameter & operator&=(const OtherType & v); + template + ofReadOnlyParameter & operator|=(const OtherType & v); + template + ofReadOnlyParameter & operator^=(const OtherType & v); + template + ofReadOnlyParameter & operator<<=(const OtherType & v); + template + ofReadOnlyParameter & operator>>=(const OtherType & v); + + ofReadOnlyParameter & set(const ParameterType & v); + + ofReadOnlyParameter & set(const std::string & name, const ParameterType & value); + ofReadOnlyParameter & set(const std::string & name, const ParameterType & value, const ParameterType & min, const ParameterType & max); void setMin(const ParameterType & min); - void setMax(const ParameterType & max); - void setInit(const ParameterType & init); + void setMax(const ParameterType & max); + void setInit(const ParameterType & init); void fromString(const std::string & str); void setParent(ofParameterGroup & _parent); - const ofParameterGroup getFirstParent() const{ + const ofParameterGroup getFirstParent() const { return parameter.getFirstParent(); } - const void* getInternalObject() const{ + const void * getInternalObject() const { return parameter.getInternalObject(); } ofParameter parameter; - template + template friend class ofParameter; friend class ofParameterGroup; friend Friend; - template + template friend class ofReadOnlyParameter; }; - -template -inline ofReadOnlyParameter::ofReadOnlyParameter(){} +template +inline ofReadOnlyParameter::ofReadOnlyParameter() { } //template //inline ofReadOnlyParameter::ofReadOnlyParameter(ofParameter & p) @@ -1232,283 +1221,269 @@ inline ofReadOnlyParameter::ofReadOnlyParameter(){} //inline ofReadOnlyParameter::ofReadOnlyParameter(ofReadOnlyParameter & p) //:parameter(p){} -template -inline ofReadOnlyParameter::ofReadOnlyParameter(const ParameterType & v) -:parameter(v){} - -template -inline ofReadOnlyParameter::ofReadOnlyParameter(const std::string& name, const ParameterType & v) -:parameter(name,v){} +template +inline ofReadOnlyParameter::ofReadOnlyParameter(const ParameterType & v) + : parameter(v) { } -template -inline ofReadOnlyParameter::ofReadOnlyParameter(const std::string& name, const ParameterType & v, const ParameterType & min, const ParameterType & max) -:parameter(name,v,min,max){} +template +inline ofReadOnlyParameter::ofReadOnlyParameter(const std::string & name, const ParameterType & v) + : parameter(name, v) { } +template +inline ofReadOnlyParameter::ofReadOnlyParameter(const std::string & name, const ParameterType & v, const ParameterType & min, const ParameterType & max) + : parameter(name, v, min, max) { } -template -inline const ParameterType & ofReadOnlyParameter::get() const{ +template +inline const ParameterType & ofReadOnlyParameter::get() const { return parameter.get(); } -template -inline const ParameterType * ofReadOnlyParameter::operator->() const{ +template +inline const ParameterType * ofReadOnlyParameter::operator->() const { return ¶meter.get(); } -template -inline ofReadOnlyParameter::operator const ParameterType & () const{ +template +inline ofReadOnlyParameter::operator const ParameterType &() const { return parameter.get(); } - -template -inline std::string ofReadOnlyParameter::getName() const{ +template +inline std::string ofReadOnlyParameter::getName() const { return parameter.getName(); } - -template -inline ParameterType ofReadOnlyParameter::getMin() const{ +template +inline ParameterType ofReadOnlyParameter::getMin() const { return parameter.getMin(); } - -template -inline ParameterType ofReadOnlyParameter::getMax() const{ +template +inline ParameterType ofReadOnlyParameter::getMax() const { return parameter.getMax(); } - -template -inline std::string ofReadOnlyParameter::toString() const{ +template +inline std::string ofReadOnlyParameter::toString() const { return parameter.toString(); } -template -std::string ofReadOnlyParameter::valueType() const{ +template +std::string ofReadOnlyParameter::valueType() const { return typeid(ParameterType).name(); } - -template -template -inline void ofReadOnlyParameter::addListener(ListenerClass * listener, ListenerMethod method, int prio){ - parameter.addListener(listener,method,prio); +template +template +inline void ofReadOnlyParameter::addListener(ListenerClass * listener, ListenerMethod method, int prio) { + parameter.addListener(listener, method, prio); } - -template -template -inline void ofReadOnlyParameter::removeListener(ListenerClass * listener, ListenerMethod method, int prio){ - parameter.removeListener(listener,method,prio); +template +template +inline void ofReadOnlyParameter::removeListener(ListenerClass * listener, ListenerMethod method, int prio) { + parameter.removeListener(listener, method, prio); } - -template -template -inline std::unique_ptr ofReadOnlyParameter::newListener(Args...args) { +template +template +inline std::unique_ptr ofReadOnlyParameter::newListener(Args... args) { return parameter.newListener(args...); } -template -inline void ofReadOnlyParameter::setName(const std::string & name){ +template +inline void ofReadOnlyParameter::setName(const std::string & name) { parameter.setName(name); } -template -inline void ofReadOnlyParameter::enableEvents(){ +template +inline void ofReadOnlyParameter::enableEvents() { parameter.enableEvents(); } -template -inline void ofReadOnlyParameter::disableEvents(){ +template +inline void ofReadOnlyParameter::disableEvents() { parameter.disableEvents(); } -template -inline bool ofReadOnlyParameter::isSerializable() const{ +template +inline bool ofReadOnlyParameter::isSerializable() const { return parameter.isSerializable(); } -template -inline bool ofReadOnlyParameter::isReadOnly() const{ +template +inline bool ofReadOnlyParameter::isReadOnly() const { return true; } -template -inline void ofReadOnlyParameter::setSerializable(bool s){ +template +inline void ofReadOnlyParameter::setSerializable(bool s) { parameter.setSerializable(s); } -template -template -inline void ofReadOnlyParameter::makeReferenceTo(ofReadOnlyParameter mom){ +template +template +inline void ofReadOnlyParameter::makeReferenceTo(ofReadOnlyParameter mom) { parameter.makeReferenceTo(mom.parameter); } -template -void ofReadOnlyParameter::makeReferenceTo(ofParameter mom){ +template +void ofReadOnlyParameter::makeReferenceTo(ofParameter mom) { parameter.makeReferenceTo(mom); } -template -inline ofReadOnlyParameter & ofReadOnlyParameter::operator=(const ofReadOnlyParameter & v){ +template +inline ofReadOnlyParameter & ofReadOnlyParameter::operator=(const ofReadOnlyParameter & v) { parameter = v.parameter; return *this; } -template -inline ofReadOnlyParameter & ofReadOnlyParameter::operator=(const ofParameter& v){ +template +inline ofReadOnlyParameter & ofReadOnlyParameter::operator=(const ofParameter & v) { parameter = v; return *this; } -template -inline const ParameterType & ofReadOnlyParameter::operator=(const ParameterType & v){ +template +inline const ParameterType & ofReadOnlyParameter::operator=(const ParameterType & v) { parameter = v; return v; } - -template -inline ParameterType ofReadOnlyParameter::operator++(int){ +template +inline ParameterType ofReadOnlyParameter::operator++(int) { return parameter++; } -template -inline ofReadOnlyParameter & ofReadOnlyParameter::operator++(){ +template +inline ofReadOnlyParameter & ofReadOnlyParameter::operator++() { return ++parameter; } - -template -inline ParameterType ofReadOnlyParameter::operator--(int){ +template +inline ParameterType ofReadOnlyParameter::operator--(int) { return parameter--; } -template -inline ofReadOnlyParameter & ofReadOnlyParameter::operator--(){ +template +inline ofReadOnlyParameter & ofReadOnlyParameter::operator--() { return --parameter; } - -template -template -inline ofReadOnlyParameter & ofReadOnlyParameter::operator+=(const OtherType & v){ - parameter+=v; +template +template +inline ofReadOnlyParameter & ofReadOnlyParameter::operator+=(const OtherType & v) { + parameter += v; return *this; } -template -template -inline ofReadOnlyParameter & ofReadOnlyParameter::operator-=(const OtherType & v){ - parameter-=v; +template +template +inline ofReadOnlyParameter & ofReadOnlyParameter::operator-=(const OtherType & v) { + parameter -= v; return *this; } -template -template -inline ofReadOnlyParameter & ofReadOnlyParameter::operator*=(const OtherType & v){ - parameter*=v; +template +template +inline ofReadOnlyParameter & ofReadOnlyParameter::operator*=(const OtherType & v) { + parameter *= v; return *this; } -template -template -inline ofReadOnlyParameter & ofReadOnlyParameter::operator/=(const OtherType & v){ - parameter/=v; +template +template +inline ofReadOnlyParameter & ofReadOnlyParameter::operator/=(const OtherType & v) { + parameter /= v; return *this; } -template -template -inline ofReadOnlyParameter & ofReadOnlyParameter::operator%=(const OtherType & v){ - parameter%=v; +template +template +inline ofReadOnlyParameter & ofReadOnlyParameter::operator%=(const OtherType & v) { + parameter %= v; return *this; } -template -template -inline ofReadOnlyParameter & ofReadOnlyParameter::operator&=(const OtherType & v){ - parameter&=v; +template +template +inline ofReadOnlyParameter & ofReadOnlyParameter::operator&=(const OtherType & v) { + parameter &= v; return *this; } -template -template -inline ofReadOnlyParameter & ofReadOnlyParameter::operator|=(const OtherType & v){ - parameter|=v; +template +template +inline ofReadOnlyParameter & ofReadOnlyParameter::operator|=(const OtherType & v) { + parameter |= v; return *this; } -template -template -inline ofReadOnlyParameter & ofReadOnlyParameter::operator^=(const OtherType & v){ - parameter^=v; +template +template +inline ofReadOnlyParameter & ofReadOnlyParameter::operator^=(const OtherType & v) { + parameter ^= v; return *this; } -template -template -inline ofReadOnlyParameter & ofReadOnlyParameter::operator<<=(const OtherType & v){ - parameter<<=v; +template +template +inline ofReadOnlyParameter & ofReadOnlyParameter::operator<<=(const OtherType & v) { + parameter <<= v; return *this; } -template -template -inline ofReadOnlyParameter & ofReadOnlyParameter::operator>>=(const OtherType & v){ - parameter>>=v; +template +template +inline ofReadOnlyParameter & ofReadOnlyParameter::operator>>=(const OtherType & v) { + parameter >>= v; return *this; } - - -template -inline ofReadOnlyParameter & ofReadOnlyParameter::set(const ParameterType & v){ +template +inline ofReadOnlyParameter & ofReadOnlyParameter::set(const ParameterType & v) { parameter.set(v); return *this; } -template -inline ofReadOnlyParameter & ofReadOnlyParameter::set(const std::string& name, const ParameterType & value){ - parameter.set(name,value); +template +inline ofReadOnlyParameter & ofReadOnlyParameter::set(const std::string & name, const ParameterType & value) { + parameter.set(name, value); return *this; } -template -inline ofReadOnlyParameter & ofReadOnlyParameter::set(const std::string& name, const ParameterType & value, const ParameterType & min, const ParameterType & max){ - parameter.set(name,value,min,max); +template +inline ofReadOnlyParameter & ofReadOnlyParameter::set(const std::string & name, const ParameterType & value, const ParameterType & min, const ParameterType & max) { + parameter.set(name, value, min, max); return *this; } - -template -inline void ofReadOnlyParameter::setMin(const ParameterType & min){ +template +inline void ofReadOnlyParameter::setMin(const ParameterType & min) { parameter.setMin(min); } -template -inline void ofReadOnlyParameter::setMax(const ParameterType & max){ +template +inline void ofReadOnlyParameter::setMax(const ParameterType & max) { parameter.setMax(max); } -template -inline void ofReadOnlyParameter::setInit(const ParameterType & init){ - parameter.setInit(init); +template +inline void ofReadOnlyParameter::setInit(const ParameterType & init) { + parameter.setInit(init); } -template -inline void ofReadOnlyParameter::fromString(const std::string & str){ +template +inline void ofReadOnlyParameter::fromString(const std::string & str) { parameter.fromString(str); } -template -std::shared_ptr ofReadOnlyParameter::newReference() const{ - return std::make_shared>(*this); +template +std::shared_ptr ofReadOnlyParameter::newReference() const { + return std::make_shared>(*this); } -template -void ofReadOnlyParameter::setParent(ofParameterGroup & _parent){ +template +void ofReadOnlyParameter::setParent(ofParameterGroup & _parent) { parameter.setParent(_parent); }