3 #include "ResourceItem.h"
11 ResourceItem::ResourceItem()
22 ResourceItem::~ResourceItem()
29 ResourceItem::SetLocation(roff_t offset
, roff_t size
)
37 ResourceItem::SetIdentity(type_code type
, int32 id
, const char* name
)
46 ResourceItem::SetOffset(roff_t offset
)
53 ResourceItem::GetOffset() const
60 ResourceItem::SetSize(roff_t size
)
70 ResourceItem::GetSize() const
77 ResourceItem::SetType(type_code type
)
84 ResourceItem::GetType() const
91 ResourceItem::SetID(int32 id
)
98 ResourceItem::GetID() const
105 ResourceItem::SetName(const char* name
)
112 ResourceItem::GetName() const
114 return fName
.String();
119 ResourceItem::SetData(const void* data
, roff_t size
)
127 memcpy(fData
, data
, fSize
);
134 ResourceItem::UnsetData()
137 delete[] (char*)fData
;
144 ResourceItem::AllocData(roff_t size
)
148 if (!fData
&& fSize
> 0)
149 fData
= new char*[fSize
];
155 ResourceItem::GetData() const
162 ResourceItem::LoadData(BPositionIO
& file
, roff_t position
, roff_t size
)
164 status_t error
= B_OK
;
168 if (fData
&& fSize
) {
169 ssize_t read
= file
.ReadAt(fOffset
, fData
, fSize
);
172 else if (read
< fSize
)
180 ResourceItem::WriteData(BPositionIO
& file
) const
182 status_t error
= (fData
? B_OK
: B_BAD_VALUE
);
183 if (error
== B_OK
&& fSize
> 0) {
184 ssize_t written
= file
.WriteAt(fOffset
, fData
, fSize
);
187 else if (written
< fSize
)
188 error
= B_FILE_ERROR
;
195 ResourceItem::PrintToStream()
197 char typeName
[4] = { fType
>> 24, (fType
>> 16) & 0xff,
198 (fType
>> 8) & 0xff, fType
& 0xff };
199 printf("resource: offset: 0x%08lx (%10ld)\n", fOffset
, fOffset
);
200 printf(" size : 0x%08lx (%10ld)\n", fSize
, fSize
);
201 printf(" type : '%.4s' (0x%8lx)\n", typeName
, fType
);
202 printf(" id : %ld\n", fID
);
203 printf(" name : `%s'\n", fName
.String());