Browse Source

- set_BagSize() used long long usigned now

- set_BaggingDate() allows time_t now
master
parent
commit
c68fc8601c
2 changed files with 16 additions and 7 deletions
  1. +3
    -1
      src/include/bagmetadata.hpp
  2. +13
    -6
      src/lib/bagmetadata.cpp

+ 3
- 1
src/include/bagmetadata.hpp View File

@@ -17,6 +17,7 @@
#include <string>
#include <map>
#include <sstream>
#include <ctime>
#include "checksum.hpp"
using namespace std;

@@ -84,9 +85,10 @@ class Bagmetadata{
void set_ContactEmail( string );
void set_ExternalDescription( string );
void set_BaggingDate( string );
void set_BaggingDate( time_t );
void set_ExternalIdentifier( string );
void set_BagSize( string );
void set_BagSize( unsigned long int); // count of bytes, the method calcs the human readable string
void set_BagSize(long long unsigned int bytes); // count of bytes, the method calcs the human readable string
void set_PayloadOxum( oxum_t );
void set_BagGroupIdentifier( string );
void set_BagCount( string );


+ 13
- 6
src/lib/bagmetadata.cpp View File

@@ -360,6 +360,12 @@ void Bagmetadata::set_BaggingDate(string BaggingDate) {
this->metadata["BaggingDate"] = BaggingDate;
}

void Bagmetadata::set_BaggingDate( std::time_t BaggingDate ) {
char datestring[100];
std::strftime( datestring, sizeof(datestring), "%Y-%m-%d", std::localtime(&BaggingDate));
this->metadata["BaggingDate"] = string(datestring);
}

void Bagmetadata::set_ExternalIdentifier(string ExternalIdentifier) {
this->metadata["ExternalIdentifier"] = ExternalIdentifier;
}
@@ -368,15 +374,16 @@ void Bagmetadata::set_BagSize(string BagSize) {
this->metadata["BagSize"] = BagSize;
}

void Bagmetadata::set_BagSize( unsigned long int bytes) {
if (bytes > (1024*1024*1024*1024) ) {
this->metadata["BagSize"] = to_string (bytes/ (1024*1024*1024*1024)) + " TB";
void Bagmetadata::set_BagSize( unsigned long long int bytes) {

if (bytes > (const unsigned long long int) (1024ull*1024*1024*1024) ) {
this->metadata["BagSize"] = to_string (bytes/ (1024ull*1024*1024*1024)) + " TB";
} else if (bytes > (1024*1024*1024) ) {
this->metadata["BagSize"] = to_string (bytes/ (1024*1024*1024)) + " GB";
this->metadata["BagSize"] = to_string (bytes/ (1024ull*1024*1024)) + " GB";
} else if (bytes > (1024*1024) ) {
this->metadata["BagSize"] = to_string (bytes/ (1024*1024)) + " MB";
this->metadata["BagSize"] = to_string (bytes/ (1024ull*1024)) + " MB";
} else if (bytes > (1024) ) {
this->metadata["BagSize"] = to_string (bytes/ (1024)) + " kB";
this->metadata["BagSize"] = to_string (bytes/ (1024ull)) + " kB";
} else {
this->metadata["BagSize"] = to_string (bytes) + " B";
}


Loading…
Cancel
Save