- Library code update
- project update (added Eigen) git-svn-id: http://moon:8086/svn/software/trunk/projects/mpsk_rx_gui@94 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
@@ -22,76 +22,18 @@
|
||||
==============================================================================
|
||||
*/
|
||||
|
||||
class SharedValueSourceUpdater : public ReferenceCountedObject,
|
||||
private AsyncUpdater
|
||||
{
|
||||
public:
|
||||
SharedValueSourceUpdater() : sourcesBeingIterated (nullptr) {}
|
||||
~SharedValueSourceUpdater() { masterReference.clear(); }
|
||||
|
||||
void update (Value::ValueSource* const source)
|
||||
{
|
||||
sourcesNeedingAnUpdate.add (source);
|
||||
|
||||
if (sourcesBeingIterated == nullptr)
|
||||
triggerAsyncUpdate();
|
||||
}
|
||||
|
||||
void valueDeleted (Value::ValueSource* const source)
|
||||
{
|
||||
sourcesNeedingAnUpdate.removeValue (source);
|
||||
|
||||
if (sourcesBeingIterated != nullptr)
|
||||
sourcesBeingIterated->removeValue (source);
|
||||
}
|
||||
|
||||
WeakReference<SharedValueSourceUpdater>::Master masterReference;
|
||||
|
||||
private:
|
||||
typedef SortedSet<Value::ValueSource*> SourceSet;
|
||||
SourceSet sourcesNeedingAnUpdate;
|
||||
SourceSet* sourcesBeingIterated;
|
||||
|
||||
void handleAsyncUpdate() override
|
||||
{
|
||||
const ReferenceCountedObjectPtr<SharedValueSourceUpdater> localRef (this);
|
||||
|
||||
{
|
||||
const ScopedValueSetter<SourceSet*> inside (sourcesBeingIterated, nullptr, nullptr);
|
||||
int maxLoops = 10;
|
||||
|
||||
while (sourcesNeedingAnUpdate.size() > 0)
|
||||
{
|
||||
if (--maxLoops == 0)
|
||||
{
|
||||
triggerAsyncUpdate();
|
||||
break;
|
||||
}
|
||||
|
||||
SourceSet sources;
|
||||
sources.swapWith (sourcesNeedingAnUpdate);
|
||||
sourcesBeingIterated = &sources;
|
||||
|
||||
for (int i = sources.size(); --i >= 0;)
|
||||
if (i < sources.size())
|
||||
sources.getUnchecked(i)->sendChangeMessage (true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (SharedValueSourceUpdater)
|
||||
};
|
||||
|
||||
static WeakReference<SharedValueSourceUpdater> sharedUpdater;
|
||||
|
||||
Value::ValueSource::ValueSource()
|
||||
{
|
||||
}
|
||||
|
||||
Value::ValueSource::~ValueSource()
|
||||
{
|
||||
if (asyncUpdater != nullptr)
|
||||
static_cast <SharedValueSourceUpdater*> (asyncUpdater.get())->valueDeleted (this);
|
||||
cancelPendingUpdate();
|
||||
}
|
||||
|
||||
void Value::ValueSource::handleAsyncUpdate()
|
||||
{
|
||||
sendChangeMessage (true);
|
||||
}
|
||||
|
||||
void Value::ValueSource::sendChangeMessage (const bool synchronous)
|
||||
@@ -103,7 +45,8 @@ void Value::ValueSource::sendChangeMessage (const bool synchronous)
|
||||
if (synchronous)
|
||||
{
|
||||
const ReferenceCountedObjectPtr<ValueSource> localRef (this);
|
||||
asyncUpdater = nullptr;
|
||||
|
||||
cancelPendingUpdate();
|
||||
|
||||
for (int i = numListeners; --i >= 0;)
|
||||
if (Value* const v = valuesWithListeners[i])
|
||||
@@ -111,22 +54,7 @@ void Value::ValueSource::sendChangeMessage (const bool synchronous)
|
||||
}
|
||||
else
|
||||
{
|
||||
SharedValueSourceUpdater* updater = static_cast <SharedValueSourceUpdater*> (asyncUpdater.get());
|
||||
|
||||
if (updater == nullptr)
|
||||
{
|
||||
if (sharedUpdater == nullptr)
|
||||
{
|
||||
asyncUpdater = updater = new SharedValueSourceUpdater();
|
||||
sharedUpdater = updater;
|
||||
}
|
||||
else
|
||||
{
|
||||
asyncUpdater = updater = sharedUpdater.get();
|
||||
}
|
||||
}
|
||||
|
||||
updater->update (this);
|
||||
triggerAsyncUpdate();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -166,24 +94,20 @@ private:
|
||||
|
||||
|
||||
//==============================================================================
|
||||
Value::Value()
|
||||
: value (new SimpleValueSource())
|
||||
Value::Value() : value (new SimpleValueSource())
|
||||
{
|
||||
}
|
||||
|
||||
Value::Value (ValueSource* const v)
|
||||
: value (v)
|
||||
Value::Value (ValueSource* const v) : value (v)
|
||||
{
|
||||
jassert (v != nullptr);
|
||||
}
|
||||
|
||||
Value::Value (const var& initialValue)
|
||||
: value (new SimpleValueSource (initialValue))
|
||||
Value::Value (const var& initialValue) : value (new SimpleValueSource (initialValue))
|
||||
{
|
||||
}
|
||||
|
||||
Value::Value (const Value& other)
|
||||
: value (other.value)
|
||||
Value::Value (const Value& other) : value (other.value)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -195,20 +119,35 @@ Value& Value::operator= (const Value& other)
|
||||
|
||||
#if JUCE_COMPILER_SUPPORTS_MOVE_SEMANTICS
|
||||
Value::Value (Value&& other) noexcept
|
||||
: value (static_cast <ReferenceCountedObjectPtr <ValueSource>&&> (other.value))
|
||||
{
|
||||
// moving a Value with listeners will lose those listeners, which
|
||||
// probably isn't what you wanted to happen!
|
||||
jassert (other.listeners.size() == 0);
|
||||
|
||||
other.removeFromListenerList();
|
||||
value = static_cast<ReferenceCountedObjectPtr<ValueSource>&&> (other.value);
|
||||
}
|
||||
|
||||
Value& Value::operator= (Value&& other) noexcept
|
||||
{
|
||||
value = static_cast <ReferenceCountedObjectPtr <ValueSource>&&> (other.value);
|
||||
// moving a Value with listeners will lose those listeners, which
|
||||
// probably isn't what you wanted to happen!
|
||||
jassert (other.listeners.size() == 0);
|
||||
|
||||
other.removeFromListenerList();
|
||||
value = static_cast<ReferenceCountedObjectPtr<ValueSource>&&> (other.value);
|
||||
return *this;
|
||||
}
|
||||
#endif
|
||||
|
||||
Value::~Value()
|
||||
{
|
||||
if (listeners.size() > 0)
|
||||
removeFromListenerList();
|
||||
}
|
||||
|
||||
void Value::removeFromListenerList()
|
||||
{
|
||||
if (listeners.size() > 0 && value != nullptr) // may be nullptr after a move operation
|
||||
value->valuesWithListeners.removeValue (this);
|
||||
}
|
||||
|
||||
|
||||
@@ -147,9 +147,9 @@ public:
|
||||
The listener is added to this specific Value object, and not to the shared
|
||||
object that it refers to. When this object is deleted, all the listeners will
|
||||
be lost, even if other references to the same Value still exist. So when you're
|
||||
adding a listener, make sure that you add it to a ValueTree instance that will last
|
||||
adding a listener, make sure that you add it to a Value instance that will last
|
||||
for as long as you need the listener. In general, you'd never want to add a listener
|
||||
to a local stack-based ValueTree, but more likely to one that's a member variable.
|
||||
to a local stack-based Value, but more likely to one that's a member variable.
|
||||
|
||||
@see removeListener
|
||||
*/
|
||||
@@ -167,7 +167,8 @@ public:
|
||||
of a ValueSource object. If you're feeling adventurous, you can create your own custom
|
||||
ValueSource classes to allow Value objects to represent your own custom data items.
|
||||
*/
|
||||
class JUCE_API ValueSource : public SingleThreadedReferenceCountedObject
|
||||
class JUCE_API ValueSource : public ReferenceCountedObject,
|
||||
private AsyncUpdater
|
||||
{
|
||||
public:
|
||||
ValueSource();
|
||||
@@ -192,8 +193,10 @@ public:
|
||||
protected:
|
||||
//==============================================================================
|
||||
friend class Value;
|
||||
SortedSet <Value*> valuesWithListeners;
|
||||
ReferenceCountedObjectPtr<ReferenceCountedObject> asyncUpdater;
|
||||
SortedSet<Value*> valuesWithListeners;
|
||||
|
||||
private:
|
||||
void handleAsyncUpdate() override;
|
||||
|
||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ValueSource)
|
||||
};
|
||||
@@ -210,10 +213,11 @@ public:
|
||||
private:
|
||||
//==============================================================================
|
||||
friend class ValueSource;
|
||||
ReferenceCountedObjectPtr <ValueSource> value;
|
||||
ListenerList <Listener> listeners;
|
||||
ReferenceCountedObjectPtr<ValueSource> value;
|
||||
ListenerList<Listener> listeners;
|
||||
|
||||
void callListeners();
|
||||
void removeFromListenerList();
|
||||
|
||||
// This is disallowed to avoid confusion about whether it should
|
||||
// do a by-value or by-reference copy.
|
||||
|
||||
@@ -409,7 +409,7 @@ public:
|
||||
|
||||
XmlElement* createXml() const
|
||||
{
|
||||
XmlElement* const xml = new XmlElement (type.toString());
|
||||
XmlElement* const xml = new XmlElement (type);
|
||||
properties.copyToXmlAttributes (*xml);
|
||||
|
||||
// (NB: it's faster to add nodes to XML elements in reverse order)
|
||||
@@ -789,6 +789,11 @@ void ValueTree::copyPropertiesFrom (const ValueTree& source, UndoManager* const
|
||||
object->copyPropertiesFrom (*(source.object), undoManager);
|
||||
}
|
||||
|
||||
int ValueTree::getReferenceCount() const noexcept
|
||||
{
|
||||
return object != nullptr ? object->getReferenceCount() : 0;
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
class ValueTreePropertyValueSource : public Value::ValueSource,
|
||||
private ValueTree::Listener
|
||||
@@ -950,6 +955,9 @@ XmlElement* ValueTree::createXml() const
|
||||
|
||||
ValueTree ValueTree::fromXml (const XmlElement& xml)
|
||||
{
|
||||
// ValueTrees don't have any equivalent to XML text elements!
|
||||
jassert (! xml.isTextElement());
|
||||
|
||||
ValueTree v (xml.getTagName());
|
||||
v.object->properties.setFromXmlAttributes (xml);
|
||||
|
||||
|
||||
@@ -318,7 +318,10 @@ public:
|
||||
/** Creates an XmlElement that holds a complete image of this node and all its children.
|
||||
|
||||
If this node is invalid, this may return nullptr. Otherwise, the XML that is produced can
|
||||
be used to recreate a similar node by calling fromXml()
|
||||
be used to recreate a similar node by calling fromXml().
|
||||
|
||||
The caller must delete the object that is returned.
|
||||
|
||||
@see fromXml
|
||||
*/
|
||||
XmlElement* createXml() const;
|
||||
@@ -490,6 +493,11 @@ public:
|
||||
*/
|
||||
static const ValueTree invalid;
|
||||
|
||||
/** Returns the total number of references to the shared underlying data structure that this
|
||||
ValueTree is using.
|
||||
*/
|
||||
int getReferenceCount() const noexcept;
|
||||
|
||||
private:
|
||||
//==============================================================================
|
||||
JUCE_PUBLIC_IN_DLL_BUILD (class SharedObject)
|
||||
|
||||
Reference in New Issue
Block a user