2 * Copyright (c) 2005-2010, Haiku, Inc.
3 * Distributed under the terms of the MIT license.
6 * DarkWyrm <darkwyrm@gmail.com>
8 #include "ResourceData.h"
12 ResourceData::ResourceData(void)
14 fTypeString("Invalid"),
25 ResourceData::ResourceData(const type_code
&code
, const int32
&id
,
26 const char *name
, char *data
,
37 fTypeString
= MakeTypeString(code
);
41 ResourceData::ResourceData(const ResourceData
&data
)
47 ResourceData::~ResourceData(void)
54 ResourceData::operator=(const ResourceData
&data
)
57 fTypeString
= data
.fTypeString
;
59 fIDString
= data
.fIDString
;
62 SetData(data
.fData
, data
.fLength
);
68 ResourceData::SetFromResource(const int32
&index
, BResources
&res
)
71 if (!res
.GetResourceInfo(index
, (type_code
*)&fType
, &fID
,
72 (const char **)&name
, &fLength
)) {
73 *this = ResourceData();
77 fTypeString
= MakeTypeString(fType
);
81 char *data
= (char *)res
.LoadResource(fType
, fID
, &fLength
);
82 SetData(data
, fLength
);
89 ResourceData::SetFromAttribute(const char *name
, BNode
&node
)
92 if (node
.GetAttrInfo(name
, &info
) != B_OK
) {
93 *this = ResourceData();
104 fTypeString
= MakeTypeString(fType
);
106 fData
= (char *)malloc(fLength
);
108 ssize_t size
= node
.ReadAttr(name
, info
.type
, 0, (void*)fData
, fLength
);
110 fLength
= (size_t) size
;
115 *this = ResourceData();
121 ResourceData::SetTo(const type_code
&code
, const int32
&id
,
122 const char *name
, char *data
, const size_t &length
)
125 fTypeString
= MakeTypeString(code
);
130 SetData(data
, length
);
136 ResourceData::SetType(const type_code
&code
)
139 fTypeString
= MakeTypeString(code
);
144 ResourceData::SetID(const int32
&id
)
153 ResourceData::SetData(const char *data
, const size_t &size
)
160 fData
= (char *)malloc(size
);
161 memcpy(fData
, data
, size
);