shared_file.hpp
Go to the documentation of this file.
1 
10 /*****************************************************************************
11 ** Ifdefs
12 *****************************************************************************/
13 
14 #ifndef ECL_DEVICES_SHARED_FILE_HPP_
15 #define ECL_DEVICES_SHARED_FILE_HPP_
16 
17 /*****************************************************************************
18 ** Cross Platform Functionality
19 *****************************************************************************/
20 
21 #include <ecl/config/ecl.hpp>
22 
23 /*****************************************************************************
24 ** Includes
25 *****************************************************************************/
26 
27 #include <map>
28 #include <string>
29 #include <ecl/exceptions/standard_exception.hpp>
30 #include <ecl/threads/mutex.hpp>
31 #include "detail/character_buffer.hpp"
32 #include "ofile.hpp"
33 #include "traits.hpp"
34 #include "modes.hpp"
35 #include "macros.hpp"
36 
37 /*****************************************************************************
38 ** Namespaces
39 *****************************************************************************/
40 
41 namespace ecl {
42 
43 /*****************************************************************************
44 ** Forward Definition
45 *****************************************************************************/
46 
47 class SharedFile;
48 
49 /*****************************************************************************
50 ** Interfaces
51 *****************************************************************************/
52 
53 namespace devices {
54 
55 /*****************************************************************************
56 ** Interface [SharedFileCommon]
57 *****************************************************************************/
64 class SharedFileCommon {
65 public:
75  SharedFileCommon(const std::string &name, ecl::WriteMode mode) ecl_throw_decl(StandardException);
76  virtual ~SharedFileCommon() {}
77 
78  friend class ecl::SharedFile;
79  friend class SharedFileManager;
80 
81 private:
82  unsigned int count;
83  ecl::Mutex mutex;
84  OFile file;
86 };
87 
88 class SharedFileManager {
89 public:
90  static SharedFileCommon* RegisterSharedFile(const std::string &name, ecl::WriteMode mode = New) ecl_throw_decl(StandardException);
91  static bool DeRegisterSharedFile(const std::string &name) ecl_throw_decl(StandardException);
92 private:
93  static ecl::Mutex mutex;
94  static std::map<std::string,SharedFileCommon*> opened_files;
95 };
96 
97 } // namespace devices
98 
99 /*****************************************************************************
100 ** Interface [SharedFile]
101 *****************************************************************************/
118 class ecl_devices_PUBLIC SharedFile {
119 public:
120  /*********************
121  ** C&D
122  **********************/
130  SharedFile() {};
144  SharedFile(const std::string &name, WriteMode mode = New) ecl_throw_decl(StandardException);
150  virtual ~SharedFile();
151 
166  bool open(const std::string &name, WriteMode mode = New) ecl_throw_decl(StandardException);
167 
168  /*********************
169  ** Shared File Methods
170  **********************/
178  unsigned int count() { return shared_instance->count; }
179 
180  /*********************
181  ** OutputDevice Methods
182  **********************/
188  bool open() { return shared_instance->file.open(); }
203  long write(const char &c) ecl_debug_throw_decl(StandardException);
219  long write(const char* s, unsigned long n) ecl_debug_throw_decl(StandardException);
228  bool flush() ecl_debug_throw_decl(StandardException);
229 
230  const Error& error() const { return shared_instance->error_handler; }
231 
232 private:
233  devices::SharedFileCommon* shared_instance;
234  devices::CharBuffer buffer;
235 };
236 
237 /*****************************************************************************
238 ** Traits [SharedFile]
239 *****************************************************************************/
245 template <>
246 class is_sink<SharedFile> : public True {};
247 
248 } // namespace ecl
249 
250 #endif /* ECL_DEVICES_SHARED_FILE_HPP_ */
#define ecl_throw_decl(exception)
Standard ecl throw exception declaration.
#define ecl_devices_PUBLIC
Error
Multi-instance (also thread-safe) output file device.
Bool< true > True
friend friend class SharedFileManager
#define ecl_debug_throw_decl(exception)
Debug mode throw exception declaration.


xbot_node
Author(s): Roc, wangpeng@droid.ac.cn
autogenerated on Sat Oct 10 2020 03:28:13