Isis 3 Programmer Reference
History.cpp
1 
6 /* SPDX-License-Identifier: CC0-1.0 */
7 #include "History.h"
8 
9 #include <fstream>
10 #include <sstream>
11 #include <string>
12 
13 #include "Application.h"
14 #include "PvlObject.h"
15 
16 using namespace std;
17 
18 namespace Isis {
22  History::History() {
23  p_history.setTerminator("");
24  }
25 
26 
31  History::History(Isis::Blob &blob) {
32  p_history.setTerminator("");
33 
34  char *blob_buffer = blob.getBuffer();
35  p_bufferSize = blob.Size();
36  p_histBuffer = new char[p_bufferSize];
37  memcpy(p_histBuffer, blob_buffer, p_bufferSize);
38  }
39 
40 
42  History::~History() {
43  if (p_histBuffer != NULL) {
44  delete [] p_histBuffer;
45  }
46  }
47 
48 
52  void History::AddEntry() {
53  PvlObject hist = Isis::iApp->History();
54  AddEntry(hist);
55  }
56 
57 
63  void History::AddEntry(Isis::PvlObject &obj) {
64  p_history.addObject(obj);
65  }
66 
67 
75  Blob History::toBlob(const QString &name) {
76  ostringstream ostr;
77  if (p_bufferSize > 0) ostr << std::endl;
78  ostr << p_history;
79  string histStr = ostr.str();
80  int bytes = histStr.size();
81 
82  int blobBufferSize = p_bufferSize+bytes;
83  char *blobBuffer = new char[blobBufferSize];
84  if (p_histBuffer != NULL) memcpy(blobBuffer, p_histBuffer, p_bufferSize);
85  const char *ptr = histStr.c_str();
86  memcpy(&blobBuffer[p_bufferSize], (void *)ptr, bytes);
87 
88  Blob newBlob(name, "History");
89  newBlob.takeData(blobBuffer, blobBufferSize);
90  return newBlob;
91  }
92 
93 
99  Pvl History::ReturnHist() {
100  Pvl pvl;
101  stringstream os;
102  for (int i = 0; i < p_bufferSize; i++) os << p_histBuffer[i];
103 
104  for (int i = 0; i < p_history.objects(); i++) {
105  os << std::endl << p_history.object(i);
106  }
107  os >> pvl;
108  return pvl;
109  }
110 }
Isis::Blob::takeData
void takeData(char *buffer, int nbytes)
Set the data stored in the BLOB without copying it.
Definition: Blob.cpp:398
Isis::PvlObject
Contains Pvl Groups and Pvl Objects.
Definition: PvlObject.h:61
Isis::Pvl
Container for cube-like labels.
Definition: Pvl.h:119
Isis::PvlObject::object
PvlObject & object(const int index)
Return the object at the specified index.
Definition: PvlObject.cpp:489
Isis::Blob::getBuffer
char * getBuffer()
Get the internal data buff of the Blob.
Definition: Blob.cpp:546
Isis::Blob::Size
int Size() const
Accessor method that returns the number of bytes in the blob data.
Definition: Blob.cpp:142
std
Namespace for the standard library.
Isis::Blob
Definition: Blob.h:51
Isis::Application::History
PvlObject History()
Creates an application history PvlObject.
Definition: Application.cpp:251
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16