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 *****************************************************************************/
64 class SharedFileCommon {
65 public:
75  SharedFileCommon(const std::string &name, ecl::WriteMode mode);
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);
91  static bool DeRegisterSharedFile(const std::string &name);
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  **********************/
130  SharedFile() {};
144  SharedFile(const std::string &name, WriteMode mode = New);
150  virtual ~SharedFile();
151 
166  bool open(const std::string &name, WriteMode mode = New);
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);
219  long write(const char* s, unsigned long n);
228  bool flush();
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_ */
ecl::WriteMode
WriteMode
Write mode for devices.
Definition: modes.hpp:41
ecl::devices::SharedFileCommon::SharedFileCommon
SharedFileCommon()
Definition: shared_file.hpp:80
ecl::Error
ecl::devices::SharedFileCommon
Interface distributed to all members of a shared output file.
Definition: shared_file.hpp:74
ecl::New
@ New
Opens a new object (deletes existing objects).
Definition: modes.hpp:50
ecl::devices::SharedFileCommon::SharedFileManager
friend class SharedFileManager
Definition: shared_file.hpp:93
macros.hpp
Macros for ecl devices.
ecl::devices::SharedFileManager::opened_files
static std::map< std::string, SharedFileCommon * > opened_files
Definition: shared_file.hpp:104
mutex.hpp
character_buffer.hpp
A generic buffer for devices.
modes.hpp
Device modes.
ecl::devices::SharedFileCommon::error_handler
Error error_handler
Definition: shared_file.hpp:99
ecl::devices::SharedFileCommon::count
unsigned int count
Definition: shared_file.hpp:96
ecl_devices_PUBLIC
#define ecl_devices_PUBLIC
Definition: macros.hpp:37
ecl::devices::SharedFileCommon::~SharedFileCommon
virtual ~SharedFileCommon()
Definition: shared_file.hpp:90
ofile.hpp
Synchronous and asynchronous file io.
ecl::devices::SharedFileCommon::mutex
ecl::Mutex mutex
Definition: shared_file.hpp:97
ecl::NoError
NoError
ecl::devices::SharedFileManager::RegisterSharedFile
static SharedFileCommon * RegisterSharedFile(const std::string &name, ecl::WriteMode mode=New)
Definition: shared_file.cpp:85
True
Bool< true > True
ecl::devices::SharedFileManager
Definition: shared_file.hpp:98
standard_exception.hpp
ecl::SharedFile
Multi-instance (also thread-safe) output file device.
Definition: shared_file.hpp:126
ecl::devices::SharedFileCommon::file
OFile file
Definition: shared_file.hpp:98
traits.hpp
Traits for devices.
ecl::devices::SharedFileManager::DeRegisterSharedFile
static bool DeRegisterSharedFile(const std::string &name)
Definition: shared_file.cpp:116
ecl
Embedded control libraries.
ecl::devices::SharedFileManager::mutex
static ecl::Mutex mutex
Definition: shared_file.hpp:103


ecl_devices
Author(s): Daniel Stonier
autogenerated on Wed Mar 2 2022 00:16:45