Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds csminit and csmpt as prototype CSM support #4143

Merged
merged 14 commits into from
Nov 25, 2020
Prev Previous commit
Next Next commit
Updated StringBlob override methods
  • Loading branch information
jessemapel committed Nov 20, 2020
commit 96086f643d10997a1ffe935f4851c4e39f19d70a
41 changes: 32 additions & 9 deletions isis/src/base/objs/StringBlob/StringBlob.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
*/
#include <string>
#include <QByteArray>
#include "StringBlob.h"
#include "Application.h"

Expand Down Expand Up @@ -41,22 +42,44 @@ namespace Isis {
* Prepare to write string to output cube
*/
void StringBlob::WriteInit() {
p_nbytes = m_string.size();
}
int bytes = m_string.size();

char *temp = p_buffer;
p_buffer = new char[p_nbytes+bytes];
if (temp != NULL) memcpy(p_buffer, temp, p_nbytes);
const char *ptr = m_string.c_str();
memcpy(&p_buffer[p_nbytes], (void *)ptr, bytes);
p_nbytes += bytes;

if (temp != NULL) delete [] temp;
}

/**
* Writes blob data to a stream
* Read binary data from an input stream into the string.
*
* @param stream Output steam blob data will be written to
* @param stream The input stream to read from.
*
* @throws IException::Io - Error writing data to stream
* @throws IException::Io - Error reading data from stream
*/
void StringBlob::WriteData(std::fstream &os) {
os.write(m_string.c_str(), p_nbytes);
if (!os.good()) {
QString msg = "Error writing data to " + p_type + " [" + p_blobName + "]";
void Blob::ReadData(std::istream &stream) {
// Read the binary data
if (p_buffer != NULL) delete [] p_buffer;
p_buffer = new char[p_nbytes];

streampos sbyte = p_startByte - 1;
stream.seekg(sbyte, std::ios::beg);
if (!stream.good()) {
QString msg = "Error preparing to read data from " + p_type +
" [" + p_blobName + "]";
throw IException(IException::Io, msg, _FILEINFO_);
}

stream.read(p_buffer, p_nbytes);
if (!stream.good()) {
QString msg = "Error reading data from " + p_type + " [" + p_blobName + "]";
throw IException(IException::Io, msg, _FILEINFO_);
}

m_string = QByteArray(p_buffer, p_nbytes);
}
}