VISH
0.2
|
Demonstration of how to define a variable from a compound type and how to access the components of each variable.This is demonstrated with a variable value that is relative to a ValuePool.
#include <ocean/plankton/VModules.hpp> #include <ocean/plankton/VObject.hpp> #include <ocean/plankton/VInteractionEvent.hpp> #include <ocean/plankton/VParameter.hpp> using namespace Wizt; struct InteractionInput : VInputValue<VInteractionEvent> { InteractionInput(const WeakPtr<VParameter>&owner) : VInputValue<VInteractionEvent>(owner) {} override void valueChanged(const RefPtr<VValueBase>&, const ValueNotifierList*, const ValueMap*) {} }; int LocalCompoundInput() { // Define an initialization value. It will not be used later. VInteractionEvent InitialValue; InitialValue.x = 12345; // Create a parameter which serves the type VInteractionEvent // This parameter can be part of a VObject, or part of an external // object, but in any case can be shared as an input of many // VObject's. RefPtr< VValueParameter<VInteractionEvent> > InteractionOwner = new VValueParameter<VInteractionEvent>( InitialValue, "default name", NullPtr() ); // // Now call the coolest function of all, which allows to "see" a member // InteractionOwner->exportMember( &VInteractionEvent::x, "x" ); // // For this parameter, we define an input object. // It will be used to modify this parameter, depending on // whatever happens to this input object. Also, the input // object will receive notification events. // RefPtr< VInputValue<VInteractionEvent> > myInput = new InteractionInput(InteractionOwner); myInput->activateNotification(); // // Define a new value pool // RefPtr<ValuePool> myPool = new ValuePool(); // Get the global value for later use RefPtr<VValue<VInteractionEvent> > GlobalEventValue = InteractionOwner->getGlobalValue(); printf("Input has %d components\n", GlobalEventValue->nComponents() ); // // Define the interaction value to be local // InteractionOwner->Localize(); RefPtr<VValue<VInteractionEvent> > EventValue = InteractionOwner->getValue( myPool, ""); printf("Input has %d components\n", EventValue->nComponents() ); RefPtr<VTypedValueBase<int> > EventXValue = InteractionOwner->getValue( myPool, "x"); if (!EventXValue) { puts("No X Value found!"); return 1; } // // Set the entire compound structure to a certain value // { VInteractionEvent ActionValue; ActionValue.x = 6677; myInput->setValue( myPool, ActionValue, 0 ); } // // Check it // { int X = 1010; if (!EventXValue->getValue(X) ) { puts("Could not get X value!"); return 2; } printf("X Values is %d\n", X); if (X != 6677) return 3; } // // Now set a component of the compound to a certain value // EventXValue->setValue(999); // // Verify for the component // { int X = 9101; if (!EventXValue->getValue(X) ) { puts("Could not get X value!"); return 4; } printf("NEW X Values is %d\n", X); if (X != 999) return 5; } // // Verify for the compound structure // { VInteractionEvent ActionValue; myInput->getValue( myPool, ActionValue); printf("Compound Values X is %d\n", ActionValue.x); } // // Check that the GLOBAL compound value is left unchanged // { VInteractionEvent ActionValue; if (!GlobalEventValue->getValue(ActionValue ) ) { return 6; } printf("Global X Values is still %d\n", ActionValue.x); } return 0; }