Add remaining files
[juce-lv2.git] / juce / source / src / containers / juce_DynamicObject.h
blobd899cb00f7600d674e95b2015ce21946c3f36e33
1 /*
2 ==============================================================================
4 This file is part of the JUCE library - "Jules' Utility Class Extensions"
5 Copyright 2004-11 by Raw Material Software Ltd.
7 ------------------------------------------------------------------------------
9 JUCE can be redistributed and/or modified under the terms of the GNU General
10 Public License (Version 2), as published by the Free Software Foundation.
11 A copy of the license is included in the JUCE distribution, or can be found
12 online at www.gnu.org/licenses.
14 JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 ------------------------------------------------------------------------------
20 To release a closed-source product which uses JUCE, commercial licenses are
21 available: visit www.rawmaterialsoftware.com/juce for more information.
23 ==============================================================================
26 #ifndef __JUCE_DYNAMICOBJECT_JUCEHEADER__
27 #define __JUCE_DYNAMICOBJECT_JUCEHEADER__
29 #include "juce_NamedValueSet.h"
30 #include "../memory/juce_ReferenceCountedObject.h"
33 //==============================================================================
34 /**
35 Represents a dynamically implemented object.
37 This class is primarily intended for wrapping scripting language objects,
38 but could be used for other purposes.
40 An instance of a DynamicObject can be used to store named properties, and
41 by subclassing hasMethod() and invokeMethod(), you can give your object
42 methods.
44 class JUCE_API DynamicObject : public ReferenceCountedObject
46 public:
47 //==============================================================================
48 DynamicObject();
50 /** Destructor. */
51 virtual ~DynamicObject();
53 //==============================================================================
54 /** Returns true if the object has a property with this name.
55 Note that if the property is actually a method, this will return false.
57 virtual bool hasProperty (const Identifier& propertyName) const;
59 /** Returns a named property.
61 This returns a void if no such property exists.
63 virtual var getProperty (const Identifier& propertyName) const;
65 /** Sets a named property. */
66 virtual void setProperty (const Identifier& propertyName, const var& newValue);
68 /** Removes a named property. */
69 virtual void removeProperty (const Identifier& propertyName);
71 //==============================================================================
72 /** Checks whether this object has the specified method.
74 The default implementation of this just checks whether there's a property
75 with this name that's actually a method, but this can be overridden for
76 building objects with dynamic invocation.
78 virtual bool hasMethod (const Identifier& methodName) const;
80 /** Invokes a named method on this object.
82 The default implementation looks up the named property, and if it's a method
83 call, then it invokes it.
85 This method is virtual to allow more dynamic invocation to used for objects
86 where the methods may not already be set as properies.
88 virtual var invokeMethod (const Identifier& methodName,
89 const var* parameters,
90 int numParameters);
92 /** Sets up a method.
94 This is basically the same as calling setProperty (methodName, (var::MethodFunction) myFunction), but
95 helps to avoid accidentally invoking the wrong type of var constructor. It also makes
96 the code easier to read,
98 The compiler will probably force you to use an explicit cast your method to a (var::MethodFunction), e.g.
99 @code
100 setMethod ("doSomething", (var::MethodFunction) &MyClass::doSomething);
101 @endcode
103 void setMethod (const Identifier& methodName,
104 var::MethodFunction methodFunction);
106 //==============================================================================
107 /** Removes all properties and methods from the object. */
108 void clear();
110 /** Returns the NamedValueSet that holds the object's properties. */
111 NamedValueSet& getProperties() noexcept { return properties; }
113 private:
114 //==============================================================================
115 NamedValueSet properties;
117 JUCE_LEAK_DETECTOR (DynamicObject);
122 #endif // __JUCE_DYNAMICOBJECT_JUCEHEADER__