88 lines
2.1 KiB
C++
88 lines
2.1 KiB
C++
#ifndef __SICCCOBJECT_H_
|
|
#define __SICCCOBJECT_H_
|
|
|
|
#include <iostream>
|
|
#include <sstream>
|
|
#include <chrono>
|
|
#include <cstdlib>
|
|
|
|
#include <jansson.h>
|
|
#include <assert.h>
|
|
|
|
class Sicccobject {
|
|
public:
|
|
Sicccobject() {} // just for test cases
|
|
Sicccobject( const std::string& file,
|
|
const std::string& ftype,
|
|
const std::string& fpath,
|
|
const size_t sz)
|
|
: filename(file),
|
|
filetype(ftype),
|
|
path(fpath),
|
|
size(sz)
|
|
{
|
|
upload_date = std::chrono::system_clock::now();
|
|
}
|
|
|
|
Sicccobject( const char *const file,
|
|
const char *const ftype,
|
|
const char *const fpath,
|
|
const size_t sz)
|
|
: filename(file),
|
|
filetype(ftype),
|
|
path(fpath),
|
|
size(sz)
|
|
{
|
|
upload_date = std::chrono::system_clock::now();
|
|
}
|
|
|
|
Sicccobject(const std::string& file,
|
|
const std::string& ftype,
|
|
const std::string& fpath,
|
|
const size_t sz,
|
|
const std::chrono::time_point<std::chrono::system_clock>& date)
|
|
: filename(file),
|
|
filetype(ftype),
|
|
path(fpath),
|
|
size(sz),
|
|
upload_date(date) { }
|
|
|
|
Sicccobject(const json_t*);
|
|
Sicccobject(const Sicccobject&);
|
|
~Sicccobject() {}
|
|
Sicccobject& operator = (const Sicccobject&);
|
|
|
|
std::string get_filename() const { return filename; }
|
|
std::string get_filetype() const { return filetype; }
|
|
std::string get_path() const { return path; }
|
|
size_t get_size() const { return size; }
|
|
std::chrono::time_point<std::chrono::system_clock>
|
|
get_uploadtime() const { return upload_date; }
|
|
|
|
std::string get_pretty_sized() const
|
|
{
|
|
std::ostringstream strm( std::ios_base::ate);
|
|
int i = 0;
|
|
size_t mysize = size;
|
|
const char* units[] = {"B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"};
|
|
while (mysize > 1024) {
|
|
mysize /= 1024;
|
|
i++;
|
|
}
|
|
assert(i < 9);
|
|
strm << mysize << units[i];
|
|
return strm.str();
|
|
}
|
|
|
|
private:
|
|
std::string filename;
|
|
std::string filetype;
|
|
std::string path;
|
|
size_t size;
|
|
std::chrono::time_point<std::chrono::system_clock> upload_date;
|
|
};
|
|
|
|
std::ostream& operator << (std::ostream&, const Sicccobject&);
|
|
|
|
#endif /* __SICCCOBJECT_H_ */
|