8#include "TableRecord.h"
14#include "IException.h"
16#include "TableField.h"
63 for (
int i = 0; i < (int)
p_fields.size(); i++) {
66 if (upTemp == upField)
return p_fields[i];
69 QString msg =
"Field [" + field +
"] does not exist in record";
102 for (
int f = 0; f <
Fields(); f++) {
104 if (field.isDouble()) {
105 vector<double> vals = field;
106 for (
unsigned int i = 0; i < vals.size(); i++) {
108 memmove(buf + sbyte, &vals[i], 8);
109 sbyte +=
sizeof(double);
112 else if (field.isInteger()) {
113 vector<int> vals = field;
114 for (
unsigned int i = 0; i < vals.size(); i++) {
116 memmove(buf + sbyte, &vals[i], 4);
117 sbyte +=
sizeof(int);
120 else if (field.isText()) {
121 QString val = (QString)field;
122 for (
int i = 0; i < field.size(); i++) {
123 if (i < (
int)val.length()) {
124 buf[sbyte] = val[i].toLatin1();
132 else if (field.isReal()) {
133 vector<float> vals = field;
134 for (
unsigned int i = 0; i < vals.size(); i++) {
136 memmove(buf + sbyte, &vals[i], 4);
137 sbyte +=
sizeof(float);
141 string msg =
"Invalid field type";
154 for (
int f = 0; f <
Fields(); f++) {
156 field = (
void *)&buf[sbyte];
157 sbyte += field.
bytes();
170 for (
int f = 0; f <
Fields(); f++) {
172 if (field.isDouble()) {
173 for (
int i = 0; i < field.size(); i++) {
174 char *swap = &buf[sbyte];
189 sbyte +=
sizeof(double);
192 else if (field.isInteger()) {
193 for (
int i = 0; i < field.size(); i++) {
194 char *swap = &buf[sbyte];
202 sbyte +=
sizeof(int);
205 else if (field.isText()) {
206 sbyte += field.
bytes();
208 else if (field.isReal()) {
209 for (
int i = 0; i < field.size(); i++) {
210 char *swap = &buf[sbyte];
218 sbyte +=
sizeof(float);
222 string msg =
"Unable to swap bytes. Invalid field type";
230 QString TableRecord::toString(
TableRecord record, QString fieldDelimiter,
bool fieldNames,
bool endLine) {
231 QString recordValues;
233 for (
int fieldIndex = 0;fieldIndex < record.
Fields();fieldIndex++) {
235 if (record[fieldIndex].size() == 1) {
236 recordValues += record[fieldIndex].name();
239 for (
int fieldValueIndex = 0;fieldValueIndex < record[fieldIndex].size();fieldValueIndex++) {
240 recordValues += record[fieldIndex].name();
241 if (record[fieldIndex].isText()) {
243 fieldValueIndex += record[fieldIndex].bytes();
249 if (fieldValueIndex != record[fieldIndex].size() - 1) {
251 recordValues += fieldDelimiter;
256 if (fieldIndex != record.
Fields() - 1) {
257 recordValues += fieldDelimiter;
261 recordValues +=
"\n";
264 for (
int fieldIndex = 0;fieldIndex < record.
Fields();fieldIndex++) {
266 recordValues += TableField::toString(record[fieldIndex], fieldDelimiter);
267 if (fieldIndex != record.
Fields() - 1) {
269 recordValues += fieldDelimiter;
273 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.
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.