From 8d91ec55b8c43bf3c857b92e735848bedbaa7155 Mon Sep 17 00:00:00 2001 From: blastmaster Date: Sat, 29 Mar 2014 16:43:17 +0100 Subject: [PATCH] implement first version of container class for stored items --- src/sicccobject.H | 67 ++++++++++++++++++++++++++++++++++++++++++++++ src/sicccobject.cc | 48 ++++++++++++++++++++++++--------- 2 files changed, 102 insertions(+), 13 deletions(-) create mode 100644 src/sicccobject.H diff --git a/src/sicccobject.H b/src/sicccobject.H new file mode 100644 index 0000000..07f10b4 --- /dev/null +++ b/src/sicccobject.H @@ -0,0 +1,67 @@ +#ifndef __SICCCOBJECT_H_ +#define __SICCCOBJECT_H_ + +#include +#include +#include + +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& date) + : filename(file), + filetype(ftype), + path(fpath), + size(sz), + upload_date(date) { } + + 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 + get_uploadtime() const { return upload_date; } + + private: + std::string filename; + std::string filetype; + std::string path; + size_t size; + std::chrono::time_point upload_date; +}; + +std::ostream& operator << (std::ostream&, const Sicccobject&); + +#endif /* __SICCCOBJECT_H_ */ diff --git a/src/sicccobject.cc b/src/sicccobject.cc index e7601bb..4289a42 100644 --- a/src/sicccobject.cc +++ b/src/sicccobject.cc @@ -1,16 +1,38 @@ -#include -#include -#include -#include +#include "sicccobject.H" -class Sicccobject { - public: - std::string filename; - std::string filetype; - size_t size; - time_t date; - Sicccobject(): filename(name), filetype(type), date(); - ~Sicccobject(); +Sicccobject::Sicccobject(const Sicccobject& obj) +{ + filename = obj.filename; + filetype = obj.filetype; + path = obj.path; + size = obj.size; + upload_date = obj.upload_date; +} +Sicccobject& +Sicccobject::operator = (const Sicccobject& obj) +{ + if (this == &obj) + return *this; -}; + this->filename = obj.filename; + this->filetype = obj.filetype; + this->path = obj.path; + this->size = obj.size; + this->upload_date = obj.upload_date; + + return *this; +} + +std::ostream& +operator << (std::ostream& out, const Sicccobject& obj) +{ + std::time_t time = + std::chrono::system_clock::to_time_t(obj.get_uploadtime()); + out << "[Filename] " << obj.get_filename() << std::endl + << "[Filetype] " << obj.get_filetype() << std::endl + << "[Path] " << obj.get_path() << std::endl + << "[Size] " << obj.get_size() << std::endl + << "[Uploaded] " << std::ctime(&time) << std::endl; + return out; +}