15#include "IException.h"
16#include "TableField.h"
17#include "PvlKeyword.h"
23 Table::Table(
Blob &blob) {
51 for (
int f = 0; f < rec.
Fields(); f++) {
52 p_label.addGroup(rec[f].pvlGroup());
70 Table::Table(
const QString &tableName) {
90 Table::Table(
const QString &tableName,
const QString &file) {
91 Blob blob(tableName,
"Table", file);
111 Table::Table(
const QString &tableName,
const QString &file,
const Pvl &fileHeader) {
112 Blob blob(tableName,
"Table");
113 blob.
Read(file, fileHeader);
124 Table::Table(
const Table &other) {
132 for (
unsigned int i = 0; i < other.
p_recbufs.size(); i++) {
150 Table::Table(
const QString &tableName,
const std::string &tableString,
const char &fieldDelimiter,
const vector<PvlKeyword> &tableAttrs) {
153 std::stringstream tableStream;
154 tableStream << tableString;
156 std::vector<std::string> tableLinesStringList;
158 while(std::getline(tableStream, line,
'\n')) {
159 tableLinesStringList.push_back(line);
162 int numOfFieldValues = tableLinesStringList.size() - 1;
164 std::string fieldNamesLineString = tableLinesStringList.front();
165 std::stringstream fieldNamesStringStream;
166 fieldNamesStringStream << fieldNamesLineString;
168 std::vector<QString> fieldNames;
169 std::string fieldNameString;
170 while(std::getline(fieldNamesStringStream, fieldNameString, fieldDelimiter)) {
171 fieldNames.push_back(QString::fromStdString(fieldNameString));
176 tableStream.seekg(0, ios::beg);
179 std::string recordString;
181 while(std::getline(tableStream, recordString,
'\n')) {
188 TableRecord tableRecord(recordString, fieldDelimiter, fieldNames, numOfFieldValues);
195 for (
int f = 0; f <
p_record.Fields(); f++) {
200 if (!tableAttrs.empty()) {
201 for (PvlKeyword attr : tableAttrs) {
222 for (
int g = 0; g <
p_label.groups(); g++) {
223 if (
p_label.group(g).isNamed(
"Field")) {
232 if (
p_label.hasKeyword(
"Association")) {
233 QString temp = (QString)
p_label[
"Association"];
234 temp = temp.toUpper();
235 if (temp ==
"SAMPLES")
p_assoc = Table::Samples;
236 if (temp ==
"LINES")
p_assoc = Table::Lines;
237 if (temp ==
"BANDS")
p_assoc = Table::Bands;
246 for (
int rec = 0; rec <
p_records; rec++) {
276 for (
unsigned int i = 0; i < other.
p_recbufs.size(); i++) {
349 return (
p_assoc == Table::Samples);
360 return (
p_assoc == Table::Lines);
371 return (
p_assoc == Table::Bands);
425 IString msg =
"Unable to add records to Isis Table ["
426 +
p_name +
"]. Bytes per record = [0 bytes].";
431 QString msg =
"Unable to add the given record with size = ["
433 +
p_name +
"] with record size = ["
460 vector<char *>::iterator it =
p_recbufs.begin();
461 for (
int i = 0; i < index; i++, it++);
490 blobLabel+=
PvlKeyword(
"ByteOrder", Isis::ByteOrderName(Isis::Lsb));
493 blobLabel+=
PvlKeyword(
"ByteOrder", Isis::ByteOrderName(Isis::Msb));
506 for (
int i = 0; i <
p_label.keywords(); i++) {
512 for (
int i = 0; i <
p_label.comments(); i++){
513 blobLabel.addComment(
p_label.comment(i));
516 for (
int g = 0; g <
p_label.groups(); g++) {
521 char *buf =
new char[nbytes];
523 for (
int rec = 0; rec <
Records(); rec++) {
550 tableValues += TableRecord::toString(table[0], fieldDelimiter,
true,
true);
552 for (
int recordIndex = 1; recordIndex < table.
Records(); recordIndex++) {
553 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.