8#include "TableRecord.h"
15#include "IException.h"
17#include "TableField.h"
34 std::vector<QString> fieldNames,
int numOfFieldValues) {
35 std::stringstream tableRecordStream;
36 tableRecordStream << tableRecordStr;
40 while(std::getline(tableRecordStream, fieldStr, fieldDelimiter)) {
42 tableField = std::stod(fieldStr);
87 for (
int i = 0; i < (int)
p_fields.size(); i++) {
90 if (upTemp == upField)
return p_fields[i];
93 QString msg =
"Field [" + field +
"] does not exist in record";
113 for (
int i = 0; i < (int)
p_fields.size(); i++) bytes +=
p_fields[i].bytes();
126 for (
int f = 0; f <
Fields(); f++) {
129 vector<double> vals = field;
130 for (
unsigned int i = 0; i < vals.size(); i++) {
132 memmove(buf + sbyte, &vals[i], 8);
133 sbyte +=
sizeof(double);
137 vector<int> vals = field;
138 for (
unsigned int i = 0; i < vals.size(); i++) {
140 memmove(buf + sbyte, &vals[i], 4);
141 sbyte +=
sizeof(int);
144 else if (field.
isText()) {
145 QString val = (QString)field;
146 for (
int i = 0; i < field.
size(); i++) {
147 if (i < (
int)val.length()) {
148 buf[sbyte] = val[i].toLatin1();
156 else if (field.
isReal()) {
157 vector<float> vals = field;
158 for (
unsigned int i = 0; i < vals.size(); i++) {
160 memmove(buf + sbyte, &vals[i], 4);
161 sbyte +=
sizeof(float);
165 string msg =
"Invalid field type";
178 for (
int f = 0; f <
Fields(); f++) {
180 field = (
void *)&buf[sbyte];
181 sbyte += field.
bytes();
194 for (
int f = 0; f <
Fields(); f++) {
197 for (
int i = 0; i < field.
size(); i++) {
198 char *swap = &buf[sbyte];
213 sbyte +=
sizeof(double);
217 for (
int i = 0; i < field.
size(); i++) {
218 char *swap = &buf[sbyte];
226 sbyte +=
sizeof(int);
229 else if (field.
isText()) {
230 sbyte += field.
bytes();
232 else if (field.
isReal()) {
233 for (
int i = 0; i < field.
size(); i++) {
234 char *swap = &buf[sbyte];
242 sbyte +=
sizeof(float);
246 string msg =
"Unable to swap bytes. Invalid field type";
254 QString TableRecord::toString(
TableRecord record, QString fieldDelimiter,
bool fieldNames,
bool endLine) {
255 QString recordValues;
257 for (
int fieldIndex = 0;fieldIndex < record.
Fields();fieldIndex++) {
259 if (record[fieldIndex].size() == 1) {
260 recordValues += record[fieldIndex].name();
263 for (
int fieldValueIndex = 0;fieldValueIndex < record[fieldIndex].size();fieldValueIndex++) {
264 recordValues += record[fieldIndex].name();
265 if (record[fieldIndex].isText()) {
267 fieldValueIndex += record[fieldIndex].bytes();
273 if (fieldValueIndex != record[fieldIndex].size() - 1) {
275 recordValues += fieldDelimiter;
280 if (fieldIndex != record.
Fields() - 1) {
281 recordValues += fieldDelimiter;
285 recordValues +=
"\n";
288 for (
int fieldIndex = 0;fieldIndex < record.
Fields();fieldIndex++) {
290 recordValues += TableField::toString(record[fieldIndex], fieldDelimiter);
291 if (fieldIndex != record.
Fields() - 1) {
293 recordValues += fieldDelimiter;
297 recordValues +=
"\n";
@ Programmer
This error is for when a programmer made an API call that was illegal.
Adds specific functionality to C++ strings.
IString UpCase()
Converst any lower case characters in the object IString with uppercase characters.
Class for storing an Isis::Table's field information.
bool isInteger() const
Determines whether the field type is Integer.
bool isDouble() const
Determines whether the field type is Double.
bool isReal() const
Determines whether the field type is Text.
@ Double
The values in the field are 8 byte doubles.
int size() const
Returns the number of values stored for the field at each record.
bool isText() const
Determines whether the field type is Text.
int bytes() const
Returns the number of bytes in the field value.
std::vector< TableField > p_fields
Vector of TableFields in the record.
TableRecord()
Constructs an empty TableRecord object. No member variables are set.
void Unpack(const char *buf)
Reads record information from the binary buffer.
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.
~TableRecord()
Destroys the TableRecord object.
void Swap(char *buf) const
Swaps bytes of the buffer, depending on the TableField::Type.
void operator+=(Isis::TableField &field)
Adds a TableField to a TableRecord.
TableField & operator[](const int field)
Returns the TableField at the specified location in the TableRecord.
This is free and unencumbered software released into the public domain.
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
Namespace for the standard library.