Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using namespace std;
- /* Take Snapshots efficiently*/
- #ifndef EFFICIENT_ON
- #define EFFICIENT_ON
- #endif
- #ifdef EFFICIENT_ON
- #define CPU_CYCLE_SKIPS 0
- #endif
- template<class type1, class type2>
- type2 conv(const type1& t1)
- {
- type2 t2 = type2();
- stringstream ss;
- ss<< t1;
- ss>> t2;
- return t2;
- }
- /* Prototype function declarations*/
- bool is_snapshot_file(const string&);
- string fname(const string&);
- void get_snap_info(basic_snap_data&);
- map<unsigned int, basic_snap_data> load_file_list();
- ULL lines_in_file(const string&);
- void sort_by_date(map<unsigned int, basic_snap_data>&);
- ID_T take_snapshot();
- string construct_snapshot_path(const ID_T&);
- bool is_valid_snapshot(const string&);
- /* ***********************************
- * Constructors for snapshot_class *
- */
- /* tasks for all constructors go here*/
- void snapshot_class::constructor_tasks(const string& s)
- {
- snapshot_class::clear();
- snapshot_class::filename = s;
- snapshot_class::load_snapshot(s);
- }
- snapshot_class::snapshot_class(const char* s)
- {
- snapshot_class::constructor_tasks(s);
- }
- snapshot_class::snapshot_class(const string& s)
- {
- snapshot_class::constructor_tasks(s);
- }
- snapshot_class::snapshot_class()
- {
- snapshot_class::clear();
- snapshot_class::id = take_snapshot();
- if(snapshot_class::id == 0)
- {
- snapshot_class::clear();
- }
- if(snapshot_class::id != 0)
- {
- snapshot_class::load_snapshot(construct_snapshot_path(snapshot_class::id));
- }
- }
- snapshot_class::snapshot_class(const char& c)
- {
- }
- snapshot_class::~snapshot_class()
- {
- snapshot_class::snapshot.reset();
- }
- /* ***********************************
- * Constructors for snapshot_class *
- * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */
- /* Snapshot_class Member functions:
- */
- /* Clears all the variables of the class*/
- void snapshot_class::clear()
- {
- snapshot_class::snapshot.reset();
- snapshot_class::filename.clear();
- snapshot_class::date.clear();
- snapshot_class::id = 0;
- }
- /* Loads a snapshot from a full path.*/
- void snapshot_class::load_snapshot(const string& s)
- {
- cls();
- cout<< endl<< endl<< endl;
- cout<< " Please wait... Loading information..."<< endl<< endl;
- bool valid = is_valid_snapshot(s);
- if(valid == false)
- {
- return;
- }
- ifstream in;
- string temps = "";
- snapshot_class::filename = s;
- in.open(snapshot_class::filename.c_str(), ios::INFILE);
- getline(in, temps);
- snapshot_class::id = conv<string, ID_T>(temps);
- getline(in, temps);
- snapshot_class::date = temps;
- snapshot_class::snapshot = make_shared<map<unsigned int, string>>();
- if(!in.good())
- {
- in.close();
- return;
- }
- while(in.good())
- {
- if(snapshot_class::snapshot->find(snapshot_class::snapshot->size()) == snapshot_class::snapshot->end())
- {
- (*snapshot_class::snapshot)[snapshot_class::snapshot->size()] = "";
- }
- getline(in, snapshot_class::snapshot->at((snapshot_class::snapshot->size() - 1)));
- }
- in.close();
- cls();
- }
- void snapshot_class::del()
- {
- remove(snapshot_class::filename.c_str());
- snapshot_class::clear();
- }
- ID_T snapshot_class::gid()
- {
- return snapshot_class::id;
- }
- string snapshot_class::gdate()
- {
- return snapshot_class::date;
- }
- map<unsigned int, string> snapshot_class::gsnap()
- {
- return *snapshot_class::snapshot;
- }
- /* Snapshot_class Member functions:
- */
- //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement