2014-03-29 16:43:17 +01:00
|
|
|
#ifndef __SICCCOBJECT_H_
|
|
|
|
#define __SICCCOBJECT_H_
|
|
|
|
|
|
|
|
#include <iostream>
|
2014-05-01 21:40:15 +02:00
|
|
|
#include <sstream>
|
2014-03-29 16:43:17 +01:00
|
|
|
#include <chrono>
|
|
|
|
#include <cstdlib>
|
|
|
|
|
2014-05-01 19:50:04 +02:00
|
|
|
#include <jansson.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
2014-03-29 16:43:17 +01:00
|
|
|
class Sicccobject {
|
2014-05-01 19:56:48 +02:00
|
|
|
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),
|
2014-05-02 00:41:38 +02:00
|
|
|
filepath(fpath),
|
2014-05-01 19:56:48 +02:00
|
|
|
size(sz)
|
|
|
|
{
|
|
|
|
upload_date = std::chrono::system_clock::now();
|
|
|
|
}
|
2014-03-29 16:43:17 +01:00
|
|
|
|
2014-05-01 19:56:48 +02:00
|
|
|
Sicccobject( const char *const file,
|
|
|
|
const char *const ftype,
|
|
|
|
const char *const fpath,
|
|
|
|
const size_t sz)
|
|
|
|
: filename(file),
|
|
|
|
filetype(ftype),
|
2014-05-02 00:41:38 +02:00
|
|
|
filepath(fpath),
|
2014-05-01 19:56:48 +02:00
|
|
|
size(sz)
|
|
|
|
{
|
|
|
|
upload_date = std::chrono::system_clock::now();
|
|
|
|
}
|
2014-03-29 16:43:17 +01:00
|
|
|
|
2014-05-01 19:56:48 +02:00
|
|
|
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),
|
2014-05-02 00:41:38 +02:00
|
|
|
filepath(fpath),
|
2014-05-01 19:56:48 +02:00
|
|
|
size(sz),
|
|
|
|
upload_date(date) { }
|
2014-03-29 16:43:17 +01:00
|
|
|
|
2014-05-01 19:50:04 +02:00
|
|
|
Sicccobject(const json_t*);
|
2014-03-29 16:43:17 +01:00
|
|
|
Sicccobject(const Sicccobject&);
|
|
|
|
~Sicccobject() {}
|
|
|
|
Sicccobject& operator = (const Sicccobject&);
|
|
|
|
|
2014-05-01 19:56:48 +02:00
|
|
|
std::string get_filename() const { return filename; }
|
|
|
|
std::string get_filetype() const { return filetype; }
|
2014-05-02 00:41:38 +02:00
|
|
|
std::string get_filepath() const { return filepath; }
|
2014-05-01 19:56:48 +02:00
|
|
|
size_t get_size() const { return size; }
|
|
|
|
std::chrono::time_point<std::chrono::system_clock>
|
|
|
|
get_uploadtime() const { return upload_date; }
|
2014-03-29 16:43:17 +01:00
|
|
|
|
2014-05-01 21:16:36 +02:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2014-03-29 16:43:17 +01:00
|
|
|
private:
|
|
|
|
std::string filename;
|
|
|
|
std::string filetype;
|
2014-05-02 00:41:38 +02:00
|
|
|
std::string filepath;
|
2014-03-29 16:43:17 +01:00
|
|
|
size_t size;
|
|
|
|
std::chrono::time_point<std::chrono::system_clock> upload_date;
|
|
|
|
};
|
|
|
|
|
|
|
|
std::ostream& operator << (std::ostream&, const Sicccobject&);
|
|
|
|
|
|
|
|
#endif /* __SICCCOBJECT_H_ */
|