sic/src/Sicobject.H

75 lines
1.2 KiB
C++
Raw Normal View History

#pragma once
2014-02-15 12:26:28 +01:00
#include <string>
#include <ctime>
2014-02-21 13:40:21 +01:00
#include <sstream>
#include <iostream>
2014-02-21 12:02:31 +01:00
#include <cassert>
2014-02-15 12:26:28 +01:00
2014-02-23 18:04:52 +01:00
#include "Routerin.H"
class Routerin;
class Sicobject
{
public:
2014-02-23 18:04:52 +01:00
Sicobject() = delete;
Sicobject(const Routerin * master) :
_routerin(master),
_isvalid(false)
{
};
2014-02-23 18:04:52 +01:00
Sicobject(const Routerin *master, unsigned int idnum, std::string fname,size_t objsize,time_t upl_date) :
_size(objsize),
_idnum(idnum),
2014-02-23 18:04:52 +01:00
_routerin(master),
_isvalid(true),
2014-02-15 12:26:28 +01:00
_upl_date(upl_date),
_fname(fname)
{
}
2014-02-21 12:02:31 +01:00
~Sicobject();
std::string get_loadurl(){
std::string retval = "files/"; //TODO add master.get_baseurl()
//TODO: add idnum
return retval;
}
2014-02-21 12:02:31 +01:00
std::string get_fname()
{
return _fname;
}
size_t get_size() { return _size;}
2014-02-21 12:02:31 +01:00
std::string bytesize_string()
{
2014-02-21 13:40:21 +01:00
std::ostringstream strm( std::ios_base::ate);
2014-02-21 12:02:31 +01:00
int i = 0;
size_t size = _size;
const char* units[] = {"B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"};
while (size > 1024) {
size /= 1024;
i++;
}
assert(i < 9);
2014-02-21 13:40:21 +01:00
strm << size << units[i];
return strm.str();
2014-02-21 12:02:31 +01:00
}
private:
size_t _size;
unsigned int _idnum;
2014-02-23 18:04:52 +01:00
const Routerin * _routerin;
bool _isvalid;
2014-02-15 12:26:28 +01:00
time_t _upl_date;
std::string _fname;
};