BusBoy  2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
DataFile.h
Go to the documentation of this file.
1 
17 #ifndef __BUSBOY_DATA_FILE_H__
18 #define __BUSBOY_DATA_FILE_H__
19 
20 #include <string>
21 #include <memory>
22 #include <mutex>
23 #include "DataFileSource.h"
24 #include "DataFileSink.h"
25 
26 namespace BUSBOY {
27 
28 class DataFileImpl;
29 
34 class DataFile {
35 
36  public:
37 
38  enum Allocation {
41  };
42 
49  DataFile(char* bytes, size_t size, const std::string& contentType, Allocation alloc = NEW);
50 
55  DataFile(std::shared_ptr<DataFileSource>& src, const std::string& contentType);
56 
57 
64  DataFile(const std::string& path, const std::string& contentType);
65 
69  DataFile(const std::string& contentType);
70 
74  void setFileSource(std::shared_ptr<DataFileSource>& src);
75 
79  std::shared_ptr<DataFileSource> getFileSource();
80 
84  void setFileSink(DataFileSink* sink);
85 
90 
95  std::string getFileName();
96 
100  void setFileName(const std::string& name);
101 
105  bool hasFileSource() const;
106 
110  bool hasFileSink() const;
111 
112  std::string getContentType() const;
113 
117  char* getBytes() const;
118 
122  size_t getSize() const;
123 
131  size_t read(char* buf, size_t num);
132 
138  size_t skip(size_t num);
139 
143  void write(char* buf, size_t num);
144 
149  void release();
150 
154  bool hasContent() const;
155 
162  std::unique_lock<std::recursive_mutex> getLock(bool doAcquire = true);
163 
164 
165  bool operator==(const DataFile& file) const;
166 
167  bool operator!=(const DataFile& file) const;
168 
169  ~DataFile();
170 
171  private:
172 
173  DataFileImpl* m_impl;
174 
175  // prevent calling these
176  DataFile();
177  DataFile(const DataFile& file);
178  DataFile& operator=(const DataFile& file);
179 
180 };
181 
182 }
183 #endif
184 
185 

Copyright 2014 Google Inc. All rights reserved.