Commit 38bfc070 authored by Mulas, Giacomo's avatar Mulas, Giacomo
Browse files

add some comments to VirtualAsciiFile

parent 9ac1d876
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -245,6 +245,8 @@ VirtualAsciiFile::VirtualAsciiFile(const VirtualAsciiFile& rhs) {
}

VirtualAsciiFile::~VirtualAsciiFile() {
  // is it necessary to pop them out one by one? isn't there the dedicated method of std::vector to clean the vector?
  // besides, shouldn't this be done anyway by the destructor of std:vector?
  while (!_file_lines->size() > 0) {
    _file_lines->pop_back();
  }
@@ -252,16 +254,20 @@ VirtualAsciiFile::~VirtualAsciiFile() {
}

void VirtualAsciiFile::append(const VirtualAsciiFile& rhs) {
  // concatenate the virtualasciifile pointed by rhs to the current one
  // can't we use the dedicated method insert of std::vector to do the appending, instead of an explicit loop?
  for (vector<string>::iterator it = rhs._file_lines->begin(); it != rhs._file_lines->end(); ++it) {
    _file_lines->push_back(*it);
  }
}

void VirtualAsciiFile::append_line(const string& line) {
  // append a line of output to the virtualasciifile
  _file_lines->push_back(line);
}

int VirtualAsciiFile::append_to_disk(const std::string& file_name) {
  // dump to disk the contents of the virtualasciifile, appending at the end of the given file_name
  int result = 0;
  fstream output_file;
  output_file.open(file_name, ios::app);
@@ -283,6 +289,7 @@ int VirtualAsciiFile::insert(int32_t position, VirtualAsciiFile& rhs, int32_t st
  int32_t final_index = position + end - start;
  if (final_index <= number_of_lines()) {
    for (int32_t li = start; li < end; li++) {
      // since here we are replacing the previous placeholder empty strings, make sure they are properly released when they are replaced (i.e. try it with a simple hello world example and pass it through valgrind)
      _file_lines->at(position++) = rhs._file_lines->at(li);
    }
  } else {
@@ -293,6 +300,7 @@ int VirtualAsciiFile::insert(int32_t position, VirtualAsciiFile& rhs, int32_t st
}

int VirtualAsciiFile::write_to_disk(const std::string& file_name) {
  // dump to disk the contents of the virtualasciifile, replacing the given file_name
  int result = 0;
  fstream output_file;
  output_file.open(file_name, ios::out);