The Vish Visualization Shell 0.3
Vish
LocalCompoundInput.cpp

Demonstration of how to define a variable from a compound type and how to access the components of each variable.

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>
{
{}
void valueChanged(const RefPtr<VValueBase>&, const ValueNotifierList*, const ValueMap*) override
{}
};
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.
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.
//
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;
}
A reference counting pointer class which keeps objects alive as long as strong pointers to these obje...
Definition RefPtr.hpp:405
A pointer class which behaves like native C++ pointers, but knows about the lifetime of the reference...
Definition RefPtr.hpp:82
Communication type for mouse and keyboard interactions.
Definition VInteractionEvent.hpp:58
int x
horizontal coordinate of mouse
Definition VInteractionEvent.hpp:60
Shortcut convenience class for VParameters that refer to a VValue<> storage of the actual parameter.
Definition VParameter.hpp:678
List of the components of a compound type.
Definition VValueBase.hpp:35
A node which serves to identify multiple instances of input alternatives for a certain value.
Definition ValueNotifier.hpp:91
A ValuePool is the home of local values of certain input objects.
Definition ValuePool.hpp:58
std::nullptr_t NullPtr
A type indicating an invalid pointer, similar to the NULL pointer in C, but type-safe.
Definition DynPtr.hpp:368
The Vish namespace.
Definition Anemone.cpp:17
Definition LocalCompoundInput.cpp:20
A VInput that actually stores its type here.
Definition VInput.hpp:219
Definition OmegaPtrCheck.cpp:14