Some additional ideas for MACAddress class


#1

I have been using MACAddress with a 3rd party API today. This API loves to feed/recieve addresses in ASCII : / so I made some changes to the class that other people may be interested in.

in juce_MACAddress.cpp

MACAddress::MACAddress (const StringRef addressStr)

{

    MemoryBlock hexRepresentation;

    hexRepresentation.loadFromHexString(addressStr);

    memcpy (address, hexRepresentation.getData(), sizeof (address));

}

...

String MACAddress::toString (const StringRef separator) const

{

    String s;


    for (size_t i = 0; i < sizeof (address); ++i)

    {

        s << String::toHexString ((int) address[i]).paddedLeft ('0', 2);


        if (i < sizeof (address) - 1)

            s << separator;

    }


    return s;

}

 

in juce_MACAddress.h

/** Creates an address from a string representation. */

    MACAddress (const StringRef address);

...

/** Returns a in the form "11-22-33-44-55-66" (dashes are the default separator) */

    String toString (const StringRef separator = "-") const;

 

I hope it's up to snuff/useful.


#2

Thanks Harry! Good request, will add that.

Any of you chaps planning on coming to the juce summit? (Let me know if Uncle D. won't allow you out for the day and I'll set him straight...)


#3

Thanks for getting them in. We don't really know about the Summit. Very busy over here (when is it not? :) ) Hopefully will be able to.