44 Blob::Blob(
const QString &name,
const QString &type) {
51 p_blobPvl.setName(p_type);
65 Blob::Blob(
const QString &name,
const QString &type,
66 const QString &file) {
71 p_labelFile =
FileName(file).expanded();
81 Blob::Blob(
const Blob &other) {
93 p_buffer =
new char[p_nbytes];
95 for (
int i = 0; i < p_nbytes; i++) {
120 p_buffer =
new char[p_nbytes];
122 for (
int i = 0; i < p_nbytes; i++) {
132 if (p_buffer != NULL)
delete [] p_buffer;
140 QString Blob::Type()
const {
149 QString Blob::Name()
const {
158 int Blob::Size()
const {
179 void Blob::Find(
const Pvl &pvl) {
183 QString blobName = p_blobName.toUpper();
184 for (
int o = 0; o < pvl.
objects(); o++) {
187 QString curName = obj[
"Name"];
188 curName = curName.toUpper();
189 if (blobName == curName) {
195 if (p_type ==
"OriginalLabel" && curName ==
"ORIGINALLABEL") {
205 QString msg =
"Invalid " + p_type +
" label format";
211 QString msg =
"Unable to find " + p_type +
" [" + p_blobName +
"]";
217 p_startByte = p_blobPvl[
"StartByte"];
218 p_nbytes = p_blobPvl[
"Bytes"];
220 if (p_blobPvl.hasKeyword(
"^" + p_type)) {
222 if (p_labelFile !=
"") {
225 p_detached = path + (QString) p_blobPvl[
"^"+p_type];
226 p_blobPvl.deleteKeyword(
"^" + p_type);
230 QString msg =
"Invalid " + p_type +
" label format";
243 void Blob::Read(
const QString &file) {
245 QString temp(
FileName(file).expanded());
253 QString msg =
"Invalid " + p_type +
" label format";
268 void Blob::Read(
const QString &file,
const Pvl &pvlLabels) {
271 QString temp(
FileName(file).expanded());
275 istm.open(temp.toAscii().data(), std::ios::in);
283 Read(pvlLabels, istm);
287 QString msg =
"Unable to open " + p_type +
" [" + p_blobName +
288 "] in file [" + temp +
"]";
303 void Blob::Read(
const Pvl &pvl, std::istream &istm) {
307 if (p_detached !=
"") {
309 dstm.open(p_detached.toAscii().data(), std::ios::in);
321 QString msg =
"Unable to read " + p_type +
" [" + p_blobName +
"]";
330 void Blob::ReadInit(){
340 void Blob::ReadData(std::istream &stream) {
342 if (p_buffer != NULL)
delete [] p_buffer;
343 p_buffer =
new char[p_nbytes];
345 streampos sbyte = p_startByte - 1;
346 stream.seekg(sbyte, std::ios::beg);
347 if (!stream.good()) {
348 QString msg =
"Error preparing to read data from " + p_type +
349 " [" + p_blobName +
"]";
353 stream.read(p_buffer, p_nbytes);
354 if (!stream.good()) {
355 QString msg =
"Error reading data from " + p_type +
" [" + p_blobName +
"]";
369 void Blob::Write(
const QString &file) {
377 os.seekp(0, std::ios::end);
378 BigInt nbytes = (BigInt) os.tellp() + (BigInt) 64;
379 p_startByte = nbytes + 1 + 1;
386 ios::openmode flags = std::ios::in | std::ios::binary | std::ios::out;
387 stream.open(file.toAscii().data(), flags);
389 QString message =
"Unable to open [" + file +
"]";
393 streampos sbyte = p_startByte - 1;
394 stream.seekp(sbyte, std::ios::beg);
395 if (!stream.good()) {
397 QString msg =
"Error preparing to write data to " +
398 p_type +
" [" + p_blobName +
"]";
406 QString msg =
"Unable to create " + p_type +
" file [" + file +
"]";
418 void Blob::Write(
Pvl &pvl, std::fstream &stm,
419 const QString &detachedFileName) {
424 streampos sbyte = stm.tellp();
428 stm.seekp(0, std::ios::end);
429 streampos eofbyte = stm.tellp();
433 if (detachedFileName !=
"") {
434 p_blobPvl +=
PvlKeyword(
"^" + p_type, detachedFileName);
438 p_blobPvl[
"StartByte"] =
toString((BigInt)sbyte);
439 p_blobPvl[
"Bytes"] =
toString(p_nbytes);
442 for (
int i = 0; i < pvl.
objects(); i++) {
443 if (pvl.
object(i).
name() == p_blobPvl.name()) {
445 if ((QString)obj[
"Name"] == (QString)p_blobPvl[
"Name"]) {
448 BigInt oldSbyte = obj[
"StartByte"];
449 int oldNbytes = (int) obj[
"Bytes"];
452 if (p_nbytes <= oldNbytes) {
453 p_blobPvl[
"StartByte"] = obj[
"StartByte"];
458 else if (((oldSbyte + oldNbytes) == eofbyte) &&
459 (eofbyte >= sbyte)) {
460 p_blobPvl[
"StartByte"] = obj[
"StartByte"];
479 stm.seekp((BigInt) sbyte - (BigInt)1);
483 if (detachedFileName !=
"") {
484 p_blobPvl.deleteKeyword(
"^" + p_type);
492 void Blob::WriteInit(){
502 void Blob::WriteData(std::fstream &stream) {
503 stream.write(p_buffer, p_nbytes);
504 if (!stream.good()) {
505 QString msg =
"Error writing data to " + p_type +
" [" + p_blobName +
"]";
519 if (obj.
isNamed(
"TABLE"))
return true;