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>
30 #include <ecl/threads/mutex.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 *****************************************************************************/
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 
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 *****************************************************************************/
119 public:
120  /*********************
121  ** C&D
122  **********************/
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:
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_ */
Interface distributed to all members of a shared output file.
Definition: shared_file.hpp:64
Embedded control libraries.
WriteMode
Write mode for devices.
Definition: modes.hpp:35
devices::SharedFileCommon * shared_instance
devices::CharBuffer buffer
A generic buffer for devices.
#define ecl_throw_decl(exception)
Traits for devices.
const Error & error() const
SharedFile()
Non-RAII style constructor, doesn&#39;t open a file.
unsigned int count()
Denotes how many instances are currently sharing this file.
Multi-instance (also thread-safe) output file device.
Simple char string buffer class for use internally by the devices.
static std::map< std::string, SharedFileCommon * > opened_files
Definition: shared_file.hpp:94
Macros for ecl devices.
Device modes.
#define ecl_devices_PUBLIC
Definition: macros.hpp:37
#define ecl_debug_throw_decl(exception)
Default action for detection of sink devices (output) (false).
Definition: traits.hpp:50
Opens a new object (deletes existing objects).
Definition: modes.hpp:36
Synchronous and asynchronous file io.
bool open()
Status flag indicating if the file is open/closed.


ecl_devices
Author(s): Daniel Stonier
autogenerated on Mon Jun 10 2019 13:08:45