struct or class
nikki via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Aug 24 04:56:42 PDT 2014
I come from languages that don't offer structs, I have this json
load function that has to keep some data and intuitively I've
written a struct, I've read about the differences, heap vs stack,
value vs reference, but know I think i am overthinking it.
Is this decent:
bool loadFromFile (string path)
{
auto data = readText(path);
JSONValue parsed = parseJSON(data);
struct AtlasSpriteData
{
SDL_Rect clipRectangle;
int xOffset;
int yOffset;
}
AtlasSpriteData[string] dict;
foreach( string name, value; parsed["frames"] ){
SDL_Rect clipRectangle;
auto spriteSourceSize =
value["spriteSourceSize"];
clipRectangle.x = to!int(frame["x"].toString());
clipRectangle.y = to!int(frame["y"].toString());
clipRectangle.w = to!int(frame["w"].toString());
clipRectangle.h = to!int(frame["h"].toString());
int xOffset = to!int(spriteSourceSize["x"].toString());
int yOffset = to!int(spriteSourceSize["y"].toString());
auto data = AtlasSpriteData(clipRectangle, xOffset, yOffset);
dict[name] = data;
}
Or should I use a class for that AtlasSpriteData?
reading about it I get the impression everytime I'll look up data
from that dictionary data will get copied ?
More information about the Digitalmars-d-learn
mailing list