44 PvlFormatPds::PvlFormatPds() {
56 PvlFormatPds::PvlFormatPds(
const QString &file) : PvlFormat(file) {
68 PvlFormatPds::PvlFormatPds(Pvl &keywordType) : PvlFormat(keywordType) {
84 QString PvlFormatPds::formatValue(
const PvlKeyword &keyword,
int num) {
86 QString name = keyword.
name().toUpper();
87 if(name ==
"OBJECT" || (name ==
"GROUP")) {
88 QString val = (QString)keyword;
97 return formatString(keyword, num);
101 return formatReal(keyword, num, accuracy(keyword));
105 return formatInteger(keyword, num, accuracy(keyword));
109 return formatHex(keyword, num, accuracy(keyword));
113 return formatBinary(keyword, num, accuracy(keyword));
117 return formatEnum(keyword, num);
121 return formatBool(keyword, num);
126 return formatUnknown(keyword, num);
129 return formatUnknown(keyword, num);
144 QString PvlFormatPds::formatString(
const PvlKeyword &keyword,
int num) {
147 bool singleUnit =
false;
150 if((num >= keyword.size()) || (keyword[num].size() == 0)) {
155 QString tmp = keyword[num][0].toUpper();
156 if((tmp ==
"N/A") || (tmp ==
"NULL") || (tmp ==
"UNK")) {
157 val +=
"\"" + tmp +
"\"";
161 val = addQuotes(val);
166 if((keyword.size() > 1) && (num == 0)) {
171 if((!singleUnit) && (keyword.unit(num).size() > 0)) {
172 QString unit = keyword.unit(num);
175 val +=
" <" + unit +
">";
179 if(num != keyword.size() - 1) {
183 else if(keyword.size() > 1) {
188 if((singleUnit) && (num == keyword.size() - 1) &&
189 (keyword.unit(num).size() > 0)) {
190 QString unit = keyword.unit(num);
193 val +=
" <" + unit +
">";
206 QString PvlFormatPds::formatReal(
const PvlKeyword &keyword,
int num,
211 bool singleUnit =
false;
214 if((num >= keyword.size()) || (keyword[num].size() == 0)) {
219 if((keyword.size() > 1) && (num == 0)) {
224 QString tmp = keyword[num].toUpper();
225 if((tmp ==
"N/A") || (tmp ==
"NULL") || (tmp ==
"UNK")) {
226 val +=
"\"" + tmp +
"\"";
228 else if(places >= 0) {
230 out << setiosflags(ios::fixed) << setprecision(places) <<
toDouble((QString)keyword[num]);
231 val += out.str().c_str();
238 if((!singleUnit) && (keyword.unit(num).size() > 0)) {
239 QString unit = keyword.unit(num);
241 val +=
" <" + unit +
">";
245 if(num != keyword.size() - 1) {
249 else if(keyword.size() > 1) {
254 if((singleUnit) && (num == keyword.size() - 1) &&
255 (keyword.unit(num).size() > 0)) {
256 QString unit = keyword.unit(num);
258 val +=
" <" + unit +
">";
271 QString PvlFormatPds::formatEnum(
const PvlKeyword &keyword,
int num) {
275 bool singleUnit =
false;
278 if((num >= keyword.size()) || (keyword[num].size() == 0)) {
283 if((keyword.size() > 1) && (num == 0)) {
288 QString tmp = keyword[num].toUpper();
289 if((tmp ==
"N/A") || (tmp ==
"NULL") || (tmp ==
"UNK")) {
290 val +=
"\"" + tmp +
"\"";
297 if((!singleUnit) && (keyword.unit(num).size() > 0)) {
298 QString unit = keyword.unit(num);
300 val +=
" <" + unit +
">";
304 if(num != keyword.size() - 1) {
308 else if(keyword.size() > 1) {
313 if((singleUnit) && (num == keyword.size() - 1) &&
314 (keyword.unit(num).size() > 0)) {
315 QString unit = keyword.unit(num);
317 val +=
" <" + unit +
">";
335 QString PvlFormatPds::formatUnknown(
const PvlKeyword &keyword,
int num) {
339 bool singleUnit =
false;
342 if((num >= keyword.size()) || (keyword[num].size() == 0)) {
347 QString tmp = keyword[num].toUpper();
348 if((tmp ==
"N/A") || (tmp ==
"NULL") || (tmp ==
"UNK")) {
349 val +=
"\"" + tmp +
"\"";
353 val = PvlFormat::addQuotes(val);
358 if((keyword.size() > 1) && (num == 0)) {
363 if((!singleUnit) && (keyword.unit(num).size() > 0)) {
364 QString unit = keyword.unit(num);
366 val +=
" <" + unit +
">";
370 if(num != keyword.size() - 1) {
374 else if(keyword.size() > 1) {
379 if((singleUnit) && (num == keyword.size() - 1) &&
380 (keyword.unit(num).size() > 0)) {
381 QString unit = keyword.unit(num);
383 val +=
" <" + unit +
">";
396 QString PvlFormatPds::formatInteger(
const PvlKeyword &keyword,
int num,
int bytes) {
400 bool singleUnit =
false;
403 if((num >= keyword.size()) || (keyword[num].size() == 0)) {
408 if((keyword.size() > 1) && (num == 0)) {
413 QString tmp = keyword[num].toUpper();
414 if((tmp ==
"N/A") || (tmp ==
"NULL") || (tmp ==
"UNK")) {
415 val +=
"\"" + tmp +
"\"";
422 if((!singleUnit) && (keyword.unit(num).size() > 0)) {
423 QString unit = keyword.unit(num);
425 val +=
" <" + unit +
">";
429 if(num != keyword.size() - 1) {
433 else if(keyword.size() > 1) {
438 if((singleUnit) && (num == keyword.size() - 1) &&
439 (keyword.unit(num).size() > 0)) {
440 QString unit = keyword.unit(num);
442 val +=
" <" + unit +
">";
455 QString PvlFormatPds::formatBinary(
const PvlKeyword &keyword,
int num,
int bits) {
459 bool singleUnit =
false;
463 if((num >= keyword.size()) || (keyword[num].size() == 0)) {
468 if((keyword.size() > 1) && (num == 0)) {
473 QString tmp = keyword[num].toUpper();
474 if((tmp ==
"N/A") || (tmp ==
"NULL") || (tmp ==
"UNK")) {
475 val +=
"\"" + tmp +
"\"";
480 string binDig =
"01";
482 tmp = binDig[value % 2] + tmp;
487 ss << right << setfill(
'0') << setw(bits) << tmp;
488 tmp = ss.str().c_str();
489 val +=
"2#" + tmp +
"#";
493 if((!singleUnit) && (keyword.unit(num).size() > 0)) {
494 QString unit = keyword.unit(num);
496 val +=
" <" + unit +
">";
500 if(num != keyword.size() - 1) {
504 else if(keyword.size() > 1) {
509 if((singleUnit) && (num == keyword.size() - 1) &&
510 (keyword.unit(num).size() > 0)) {
511 QString unit = keyword.unit(num);
513 val +=
" <" + unit +
">";
528 QString PvlFormatPds::formatHex(
const PvlKeyword &keyword,
int num,
int bytes) {
532 bool singleUnit =
false;
535 if((num >= keyword.size()) || (keyword[num].size() == 0)) {
540 if((keyword.size() > 1) && (num == 0)) {
545 QString tmp = keyword[num].toUpper();
546 if((tmp ==
"N/A") || (tmp ==
"NULL") || (tmp ==
"UNK")) {
547 val +=
"\"" + tmp +
"\"";
552 ss << hex << (
unsigned short int)
toInt((QString)keyword[num]);
554 else if(bytes == 4) {
555 ss << hex << (
unsigned int)
toInt((QString)keyword[num]);
558 ss << hex <<
toBigInt((QString)keyword[num]);
560 QString h = ss.str().c_str();
562 val +=
"16#" + h +
"#";
566 if((!singleUnit) && (keyword.unit(num).size() > 0)) {
567 QString unit = keyword.unit(num);
569 val +=
" <" + unit +
">";
573 if(num != keyword.size() - 1) {
577 else if(keyword.size() > 1) {
582 if((singleUnit) && (num == keyword.size() - 1) &&
583 (keyword.unit(num).size() > 0)) {
584 QString unit = keyword.unit(num);
586 val +=
" <" + unit +
">";
599 QString PvlFormatPds::formatBool(
const PvlKeyword &keyword,
int num) {
605 if((num >= keyword.size()) || (keyword[num].size() == 0)) {
610 if((keyword.size() > 1) && (num == 0)) {
615 QString tmp = keyword[num];
617 if((tmp ==
"N/A") || (tmp ==
"NULL") || (tmp ==
"UNK")) {
618 val +=
"\"" + tmp +
"\"";
625 if(num != keyword.size() - 1) {
629 else if(keyword.size() > 1) {
644 QString PvlFormatPds::formatName(
const PvlKeyword &keyword) {
645 QString text = keyword.name();
646 text = text.toUpper();
657 QString PvlFormatPds::formatEnd(
const QString name,
658 const PvlKeyword &keyword) {
659 QString left = name.toUpper();
661 QString right = (QString)keyword;
662 right = right.toUpper();
677 QString PvlFormatPds::addQuotes(
const QString value) {
681 bool quoteValue =
true;
682 bool singleQuoteValue =
false;
683 if(val.contains(
" ")) {
684 if(val.contains(
"\"")) {
685 singleQuoteValue =
true;
693 singleQuoteValue =
false;
696 else if(val[0] ==
'"') {
697 singleQuoteValue =
false;
700 else if(val[0] ==
'\'') {
701 singleQuoteValue =
false;
706 val =
"\"" + val +
"\"";
708 else if(singleQuoteValue) {
709 val =
"'" + val +
"'";
long long int BigInt
Big int.
int toInt(const QString &string)
Global function to convert from a string to an integer.
Namespace for the standard library.
BigInt toBigInt(const QString &string)
Global function to convert from a string to a "big" integer.
double toDouble(const QString &string)
Global function to convert from a string to a double.
A single keyword-value pair.
KeywordType
The different types of keywords that can be formatted.
QString name() const
Returns the keyword name.
Namespace for ISIS/Bullet specific routines.