Raspberry Cloud
CloudFileList.h
1 #ifndef _CLOUDFILELIST_H
2 #define _CLOUDFILELIST_H
3 
4 #include "fileModel\FileDescriptor.h"
5 #include <string>
6 #include <fstream>
7 #include <list>
8 
10 public:
11  list<FileDescriptor*>* getFileTree() {
12  LOG_ENTER_EXIT;
13 
14  return &fileTree;
15  }
16 
17  void save(){
18  std::ofstream out(persPath);
19  char separator = '\n';
20 
21  out << fileTree.size();
22  out << separator;
23 
24  for each (FileDescriptor* fd in fileTree){
25  string fileID = fd->getFileID();
26  out << fileID;
27  out << separator;
28 
29  long fSize = fd->getSize();
30  if (fSize == 0){
31  cout << "SIZE NOT SET!";
32  }
33  out << fSize;
34  out << separator;
35 
36  vector<Fragment> frags = fd->getFragments();
37  out << frags.size();
38  out << separator;
39 
40  for each (Fragment frag in frags){
41  string cloudFileID = frag.getCloudFileID();
42  out << cloudFileID;
43  out << separator;
44  string cloudID = frag.getCloudId();
45  out << cloudID;
46  out << separator;
47  }
48  }
49 
50  out.close();
51  }
52 
53  void load(){
54  std::ifstream in(persPath);
55 
56  int IfileTreeSize;
57  int IfragSize;
58  long IfileSize;
59  string fileSize;
60  string fileTreeSize;
61  string fileID;
62  string fragSize;
63  string cloudFileID;
64  string cloudID;
65  getline(in, fileTreeSize);
66  IfileTreeSize = stoi(fileTreeSize);
67 
68  for (int i = 0; i < IfileTreeSize; i++){
69  getline(in, fileID);
70  FileDescriptor* row = new FileDescriptor(fileID);
71 
72  getline(in, fileSize);
73  IfileSize = stol(fileSize);
74  row->setSize(IfileSize);
75 
76  getline(in, fragSize);
77  IfragSize = stoi(fragSize);
78  vector<Fragment>* fragments = new vector<Fragment>;
79  for (int j = 0; j < IfragSize; j++){
80  getline(in, cloudFileID);
81  getline(in, cloudID);
82  Fragment* f = new Fragment(cloudID, cloudFileID);
83  fragments->push_back(*(f));
84  }
85  row->setFragments(*(fragments));
86  fileTree.push_back(row);
87  }
88 
89  in.close();
90  }
91 
92  void setPersPath(string _p){
93  persPath = _p;
94  }
95 
96 private:
97  string persPath;
98  list<FileDescriptor*> fileTree;
99 
100 };
101 
102 #endif //_CLOUDFILELIST_H
string getCloudFileID()
Definition: CloudFile.cpp:19
Definition: FileDescriptor.h:17
string getFileID()
Definition: FileDescriptor.cpp:31
vector< Fragment > getFragments()
Definition: FileDescriptor.cpp:36
string getCloudId()
Definition: CloudFile.cpp:14
Definition: Fragment.h:10
void setFragments(vector< Fragment > _fragments)
Definition: FileDescriptor.cpp:26
Definition: CloudFileList.h:9