15#include "IException.h"
16#include "TableField.h"
21 Table::Table(
Blob &blob) {
49 for (
int f = 0; f < rec.
Fields(); f++) {
50 p_label.addGroup(rec[f].pvlGroup());
68 Table::Table(
const QString &tableName) {
68 Table::Table(
const QString &tableName) {
…}
88 Table::Table(
const QString &tableName,
const QString &file) {
89 Blob blob(tableName,
"Table", file);
88 Table::Table(
const QString &tableName,
const QString &file) {
…}
109 Table::Table(
const QString &tableName,
const QString &file,
const Pvl &fileHeader) {
110 Blob blob(tableName,
"Table");
111 blob.
Read(file, fileHeader);
109 Table::Table(
const QString &tableName,
const QString &file,
const Pvl &fileHeader) {
…}
122 Table::Table(
const Table &other) {
130 for (
unsigned int i = 0; i < other.
p_recbufs.size(); i++) {
122 Table::Table(
const Table &other) {
…}
148 Table::Table(
const QString &tableName,
const std::string &tableString,
const char &fieldDelimiter) {
151 std::stringstream tableStream;
152 tableStream << tableString;
154 std::vector<std::string> tableLinesStringList;
156 while(std::getline(tableStream, line,
'\n')) {
157 tableLinesStringList.push_back(line);
160 int numOfFieldValues = tableLinesStringList.size() - 1;
162 std::string fieldNamesLineString = tableLinesStringList.front();
163 std::stringstream fieldNamesStringStream;
164 fieldNamesStringStream << fieldNamesLineString;
166 std::vector<QString> fieldNames;
167 std::string fieldNameString;
168 while(std::getline(fieldNamesStringStream, fieldNameString, fieldDelimiter)) {
169 fieldNames.push_back(QString::fromStdString(fieldNameString));
174 tableStream.seekg(0, ios::beg);
177 std::string recordString;
179 while(std::getline(tableStream, recordString,
'\n')) {
186 TableRecord tableRecord(recordString, fieldDelimiter, fieldNames, numOfFieldValues);
193 for (
int f = 0; f <
p_record.Fields(); f++) {
148 Table::Table(
const QString &tableName,
const std::string &tableString,
const char &fieldDelimiter) {
…}
213 for (
int g = 0; g <
p_label.groups(); g++) {
214 if (
p_label.group(g).isNamed(
"Field")) {
223 if (
p_label.hasKeyword(
"Association")) {
224 QString temp = (QString)
p_label[
"Association"];
225 temp = temp.toUpper();
226 if (temp ==
"SAMPLES")
p_assoc = Table::Samples;
227 if (temp ==
"LINES")
p_assoc = Table::Lines;
228 if (temp ==
"BANDS")
p_assoc = Table::Bands;
237 for (
int rec = 0; rec <
p_records; rec++) {
267 for (
unsigned int i = 0; i < other.
p_recbufs.size(); i++) {
340 return (
p_assoc == Table::Samples);
351 return (
p_assoc == Table::Lines);
362 return (
p_assoc == Table::Bands);
416 IString msg =
"Unable to add records to Isis Table ["
417 +
p_name +
"]. Bytes per record = [0 bytes].";
422 QString msg =
"Unable to add the given record with size = ["
424 +
p_name +
"] with record size = ["
451 vector<char *>::iterator it =
p_recbufs.begin();
452 for (
int i = 0; i < index; i++, it++);
481 blobLabel+=
PvlKeyword(
"ByteOrder", Isis::ByteOrderName(Isis::Lsb));
484 blobLabel+=
PvlKeyword(
"ByteOrder", Isis::ByteOrderName(Isis::Msb));
497 for (
int i = 0; i <
p_label.keywords(); i++) {
503 for (
int i = 0; i <
p_label.comments(); i++){
504 blobLabel.addComment(
p_label.comment(i));
507 for (
int g = 0; g <
p_label.groups(); g++) {
512 char *buf =
new char[nbytes];
514 for (
int rec = 0; rec <
Records(); rec++) {
541 tableValues += TableRecord::toString(table[0], fieldDelimiter,
true,
true);
543 for (
int recordIndex = 1; recordIndex < table.
Records(); recordIndex++) {
544 tableValues += TableRecord::toString(table[recordIndex], fieldDelimiter);
void Read(const QString &file, const std::vector< PvlKeyword > keywords=std::vector< PvlKeyword >())
This method reads Pvl values from a specified file.
void Write(const QString &file)
Write the blob data out to a file.
char * getBuffer()
Get the internal data buff of the Blob.
PvlObject & Label()
Accessor method that returns a PvlObject containing the Blob label.
void takeData(char *buffer, int nbytes)
Set the data stored in the BLOB without copying it.
@ Unknown
A type of error that cannot be classified as any of the other error types.
Adds specific functionality to C++ strings.
Container for cube-like labels.
A single keyword-value pair.
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 ...
Class for storing an Isis::Table's field information.
Class for storing Table blobs information.
~Table()
Destroys the Table object.
QString p_name
The name of the Table.
int RecordSize() const
Returns the number of bytes per record.
int RecordFields() const
Returns the number of fields per record.
bool IsSampleAssociated()
Checks to see if association is Samples.
Association p_assoc
Association Type of the table.
void Delete(const int index)
Deletes a TableRecord from the Table.
int p_records
Holds record count read from labels, may differ from the size of p_recbufs.
int Records() const
Returns the number of records.
PvlObject & Label()
The Table's label.
void Write(const QString &file)
Write the Table to a file.
bool p_swap
Only used for reading.
void operator+=(TableRecord &rec)
Adds a TableRecord to the Table.
void SetAssociation(const Table::Association assoc)
Sets the association to the input parameter.
TableRecord & operator[](const int index)
Reads a TableRecord from the Table.
QString Name() const
The Table's name.
std::vector< char * > p_recbufs
Buffers containing record values.
TableRecord p_record
The current table record.
bool IsBandAssociated()
Checks to see if association is Bands.
bool IsLineAssociated()
Checks to see if association is Lines.
Table & operator=(const Isis::Table &other)
Sets the Table equal to the input Table object.
void Clear()
Clear the table of all records.
void Update(const TableRecord &rec, const int index)
Updates a TableRecord.
void initFromBlob(Blob &blob)
Initialize a Table from a Blob that has been read from a file.
static QString toString(Table table, QString fieldDelimiter=",")
Convert the data from a Table into a string.
PvlObject p_label
The label for storing additional information.
Blob toBlob() const
Serialze the Table to a Blob that can be written to a file.
int RecordSize() const
Returns the number of bytes per record.
int Fields() const
Returns the number of fields that are currently in the record.
void Pack(char *buf) const
Writes record information into the binary buffer.
ByteOrder
Tests the current architecture for byte order.
This is free and unencumbered software released into the public domain.
bool IsLsb()
Return true if this host is an LSB first machine and false if it is not.
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
bool IsMsb()
Return true if this host is an MSB first machine and false if it is not.
Namespace for the standard library.