13 #include <ecl/config/ecl.hpp> 25 #include "../../include/ecl/devices/shared_file.hpp" 53 if ( !file.open(name,mode) ) {
54 error_handler = file.error();
57 error_handler = file.error();
76 std::map<std::string,SharedFileCommon*>::iterator iter = opened_files.find(name);
78 if ( iter != opened_files.end() ) {
82 iter->second->
count += 1;
83 shared_instance = iter->second;
90 opened_files.insert(std::pair<string,SharedFileCommon*>(name,shared_instance));
92 shared_instance = NULL;
97 return shared_instance;
107 std::map<std::string,SharedFileCommon*>::iterator iter = opened_files.find(name);
109 if ( iter == opened_files.end() ) {
113 if ( iter->second->count == 1 ) {
115 opened_files.erase(iter);
117 iter->second->count -= 1;
136 shared_instance(NULL)
158 if ( shared_instance == NULL ) {
159 shared_instance->error_handler =
OpenError;
162 shared_instance->error_handler =
NoError;
166 shared_instance->error_handler =
OpenError;
172 long n = buffer.append(c);
173 if ( buffer.full() ) {
182 unsigned int no_written = 0;
183 while ( no_written < n ) {
184 no_written += buffer.append(s+no_written,n-no_written);
185 if ( buffer.full() ) {
197 written = shared_instance->file.write(buffer.c_ptr(), buffer.size() );
199 shared_instance->error_handler = shared_instance->file.error();
204 shared_instance->error_handler = shared_instance->file.error();
Interface distributed to all members of a shared output file.
Embedded control libraries.
WriteMode
Write mode for devices.
#define ecl_throw(exception)
#define ecl_throw_decl(exception)
SharedFile()
Non-RAII style constructor, doesn't open a file.
static SharedFileCommon * RegisterSharedFile(const std::string &name, ecl::WriteMode mode=New) ecl_throw_decl(StandardException)
static std::map< std::string, SharedFileCommon * > opened_files
static bool DeRegisterSharedFile(const std::string &name) ecl_throw_decl(StandardException)
bool flush() ecl_debug_throw_decl(StandardException)
Flush the internal buffer.
#define ecl_debug_catch(exception)
#define ecl_debug_throw_decl(exception)
long write(const char &c) ecl_debug_throw_decl(StandardException)
Write a character to the buffer.
#define ecl_debug_throw(exception)
virtual ~SharedFile()
Automatic cleaner for shared files.
#define ecl_catch(exception)
bool open()
Status flag indicating if the file is open/closed.