16#include "IException.h"
50 const QString &file) {
106 for (
int i = 0; i <
p_nbytes; i++) {
172 for (
int o = 0; o < pvl.
objects(); o++) {
175 QString curName = obj[
"Name"];
176 curName = curName.toUpper();
177 if (blobName == curName) {
179 if (!keywords.empty()){
180 bool keywordFound =
true;
184 if (blobKeyword == keyword && !blobKeyword.
isEquivalent(keyword[0])) {
185 keywordFound =
false;
190 keywordFound =
false;
207 if (
p_type ==
"OriginalLabel" && curName ==
"ORIGINALLABEL") {
217 QString msg =
"Invalid " +
p_type +
" label format";
242 QString msg =
"Invalid " +
p_type +
" label format";
255 void Blob::Read(
const QString &file,
const std::vector<PvlKeyword> keywords) {
257 QString temp(
FileName(file).expanded());
265 QString msg =
"Invalid " +
p_type +
" label format";
268 Read(file, pvl, keywords);
255 void Blob::Read(
const QString &file,
const std::vector<PvlKeyword> keywords) {
…}
279 void Blob::Read(
const QString &file,
const Pvl &pvlLabels,
const std::vector<PvlKeyword> keywords) {
281 QString temp(
FileName(file).expanded());
285 istm.open(temp.toLatin1().data(), std::ios::in);
293 Read(pvlLabels, istm, keywords);
298 "] in file [" + temp +
"]";
279 void Blob::Read(
const QString &file,
const Pvl &pvlLabels,
const std::vector<PvlKeyword> keywords) {
…}
313 void Blob::Read(
const Pvl &pvl, std::istream &istm,
const std::vector<PvlKeyword> keywords){
319 dstm.open(
p_detached.toLatin1().data(), std::ios::in);
313 void Blob::Read(
const Pvl &pvl, std::istream &istm,
const std::vector<PvlKeyword> keywords) {
…}
357 stream.seekg(sbyte, std::ios::beg);
358 if (!stream.good()) {
359 QString msg =
"Error preparing to read data from " +
p_type +
365 if (!stream.good()) {
366 QString msg =
"Error reading data from " +
p_type +
" [" +
p_blobName +
"]";
383 char *buf =
new char[nbytes];
384 memcpy(buf, buffer, nbytes);
425 os.seekp(0, std::ios::end);
434 ios::openmode flags = std::ios::in | std::ios::binary | std::ios::out;
435 stream.open(file.toLatin1().data(), flags);
437 QString message =
"Unable to open [" + file +
"]";
442 stream.seekp(sbyte, std::ios::beg);
443 if (!stream.good()) {
445 QString msg =
"Error preparing to write data to " +
454 QString msg =
"Unable to create " +
p_type +
" file [" + file +
"]";
467 const QString &detachedFileName,
bool overwrite) {
472 streampos sbyte = stm.tellp();
476 stm.seekp(0, std::ios::end);
477 streampos eofbyte = stm.tellp();
481 if (detachedFileName !=
"") {
494 for (
int i = 0; i < pvl.
objects(); i++) {
497 if ((QString)obj[
"Name"] == (QString)
p_blobPvl[
"Name"]) {
500 BigInt oldSbyte = obj[
"StartByte"];
501 int oldNbytes = (int) obj[
"Bytes"];
505 p_blobPvl[
"StartByte"] = obj[
"StartByte"];
510 else if (((oldSbyte + oldNbytes) == eofbyte) &&
511 (eofbyte >= sbyte)) {
512 p_blobPvl[
"StartByte"] = obj[
"StartByte"];
528 if (!found || !overwrite) {
536 if (detachedFileName !=
"") {
566 if (!stream.good()) {
581 if (obj.
isNamed(
"TABLE"))
return true;
PvlObject p_blobPvl
Pvl Blob object.
int Size() const
Accessor method that returns the number of bytes in the blob data.
void setData(const char *buffer, int nbytes)
Set the data stored in the BLOB.
Blob(const QString &name, const QString &type)
Constructs a Blob object using a name and type.
void Read(const QString &file, const std::vector< PvlKeyword > keywords=std::vector< PvlKeyword >())
This method reads Pvl values from a specified file.
QString p_labelFile
The file containing the labels.
void Write(const QString &file)
Write the blob data out to a file.
QString Type() const
Accessor method that returns a string containing the Blob type.
void Find(const Pvl &pvl, const std::vector< PvlKeyword > keywords=std::vector< PvlKeyword >())
This method searches the given Pvl for the Blob by the Blob's type and name.
BigInt p_startByte
Byte blob data starts at in buffer.
virtual void WriteInit()
This virtual method for classes that inherit Blob.
virtual void ReadInit()
This virtual method for classes that inherit Blob.
QString Name() const
Accessor method that returns a string containing the Blob name.
char * getBuffer()
Get the internal data buff of the Blob.
virtual void WriteData(std::fstream &os)
Writes blob data to a stream.
PvlObject & Label()
Accessor method that returns a PvlObject containing the Blob label.
QString p_type
Type of data stored in the buffer.
QString p_detached
Used for reading detached blobs.
int p_nbytes
Size of blob data (in bytes)
void takeData(char *buffer, int nbytes)
Set the data stored in the BLOB without copying it.
Blob & operator=(const Blob &other)
This makes the two blob objects exactly the same (copies the blob)
virtual ~Blob()
Destroys the Blob object.
char * p_buffer
Buffer blob data is stored in.
virtual void ReadData(std::istream &is)
Read binary data from an input stream into the Blob object.
QString p_blobName
Name of the Blob object.
File name manipulation and expansion.
QString path() const
Returns the path of the file name.
QString expanded() const
Returns a QString of the full file name including the file path, excluding the attributes.
@ Unknown
A type of error that cannot be classified as any of the other error types.
@ Programmer
This error is for when a programmer made an API call that was illegal.
@ Io
A type of error that occurred when performing an actual I/O operation.
bool isNamed(const QString &match) const
Returns whether the given string is equal to the container name or not.
QString name() const
Returns the container name.
Container for cube-like labels.
void write(const QString &file)
Opens and writes PVL information to a file and handles the end of line sequence.
void read(const QString &file)
Loads PVL information from a stream.
A single keyword-value pair.
bool isEquivalent(QString string1, int index=0) const
Checks to see if a value with a specified index is equivalent to another QString.
Contains Pvl Groups and Pvl Objects.
bool hasKeyword(const QString &kname, FindOptions opts) const
See if a keyword is in the current PvlObject, or deeper inside other PvlObjects and Pvlgroups within ...
PvlObjectIterator findObject(const QString &name, PvlObjectIterator beg, PvlObjectIterator end)
Find the index of object with a specified name, between two indexes.
int objects() const
Returns the number of objects.
PvlObject & object(const int index)
Return the object at the specified index.
void addObject(const PvlObject &object)
Add a PvlObject.
PvlKeyword & findKeyword(const QString &kname, FindOptions opts)
Finds a keyword in the current PvlObject, or deeper inside other PvlObjects and Pvlgroups within this...
QString FileOpen(const QString &filename)
This error should be used when a file could not be opened.
This is free and unencumbered software released into the public domain.
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
bool IsBlob(PvlObject &obj)
Checks pvl object and returns whether or not it is a Blob.
long long int BigInt
Big int.
Namespace for the standard library.