Help with basic templating of Point<int>?

Hi,
I am no programmer and I don’t know any. I can’t get the following addition to work in varaiant.h. Any help would be much appreciated. I have tried typedefing

point<int>

, changing

template <typename Type> 

to

template <class Type>

and many other options. No luck.
Thank you

Here is the code I am having difficulty with

    template <> struct VariantConverter<Point<int>>
    {
        static Point<int> fromVar (const var& v)
        {
            return Point<int>
            (
             { v[0].operator int(), v[1].operator int() }
             );
        }
        static var toVar (const Point<int>& p)
        {
            return Array<var>(
                               { p.getX(), p.getY() }
                               );
        }
    };

perhaps something like

template <>
struct VariantConverter<Point<int>>
{
    static Point<int> fromVar (const var& v)           { return { v[0], v[1] }; }
    static var toVar (const Point<int>& p)             { return Array<var> { p.x, p.y }; }
};

Hi Jules,
I am taking my day off, but that didn’t work for me. I will try reinstalling JUCE tomorrow. Maybe I have messed up the JUCE code somewhere.
Thank you.

It would be useful if you explained how it didn’t work for you? (Show your code that tries using it.)

Both versions working now. I haven’t changed anything yet. Was getting two Xcode errors despite many variations. I was not implementing any instances yet.
The errors were

/Tools/JUCE/modules/juce_core/containers/juce_Variant.h:41:18: Expected unqualified-id

and

/Tools/JUCE/modules/juce_core/containers/juce_Variant.h:343:46: Expected ‘>’

Not sure what that was, but I am very happy.
Thank you Jules and Xenakios.

1 Like

Hi,
Once I test

    CachedValue<juce::Point<int>>  pointTest;

the errors start again. The code assumes one get an

Array<var>

from a

var& 

The code doesn’t appear to work even with a further templated passing of

property.getArray()

from cached_value.h.

Anyone have any tricky thoughts on how to make this less tricky. Once one can save Point to a cachedValue, then one can translate the principle to further types like Rectangles. This will make it easy to save these types to valuetree via linked cachedValues, which has a lot of uses.
Thank you

CachedValue referTo not working has a better idea.

They use StringArray rather than Array.

Hi,
Programming has those nightmare days all blurred into one. Trying to get the basic cachedValue working has been part of a little nightmare. I am using Dave’s variant converter.

    template <> struct VariantConverter<Colour>
    {
        static Colour fromVar (const var& v)
        {
            return Colour::fromString ( v.toString() );
        }
        static var toVar (const Colour& c)
        {
            return c.toString();
        }
    };

with

     CachedValue<Colour> test;
     Colour colourTest;
     ValueTree tempColourTree;

and

     colourTest      =  Colours::black;
     tempColourTree  =  valueTree.getChildWithName("colourTest");
     test.referTo (tempColourTree, "Colour", nullptr);
     test.setValue (colourTest, nullptr);

Am I missing something?
Thank you