shared_file.hpp
Go to the documentation of this file.
00001 
00010 /*****************************************************************************
00011 ** Ifdefs
00012 *****************************************************************************/
00013 
00014 #ifndef ECL_DEVICES_SHARED_FILE_HPP_
00015 #define ECL_DEVICES_SHARED_FILE_HPP_
00016 
00017 /*****************************************************************************
00018 ** Cross Platform Functionality
00019 *****************************************************************************/
00020 
00021 #include <ecl/config/ecl.hpp>
00022 
00023 /*****************************************************************************
00024 ** Includes
00025 *****************************************************************************/
00026 
00027 #include <map>
00028 #include <string>
00029 #include <ecl/exceptions/standard_exception.hpp>
00030 #include <ecl/threads/mutex.hpp>
00031 #include "detail/character_buffer.hpp"
00032 #include "ofile.hpp"
00033 #include "traits.hpp"
00034 #include "modes.hpp"
00035 #include "macros.hpp"
00036 
00037 /*****************************************************************************
00038 ** Namespaces
00039 *****************************************************************************/
00040 
00041 namespace ecl {
00042 
00043 /*****************************************************************************
00044 ** Forward Definition
00045 *****************************************************************************/
00046 
00047 class SharedFile;
00048 
00049 /*****************************************************************************
00050 ** Interfaces
00051 *****************************************************************************/
00052 
00053 namespace devices {
00054 
00055 /*****************************************************************************
00056 ** Interface [SharedFileCommon]
00057 *****************************************************************************/
00064 class SharedFileCommon {
00065 public:
00066     SharedFileCommon() : error_handler(NoError) {};
00075     SharedFileCommon(const std::string &name, ecl::WriteMode mode) ecl_throw_decl(StandardException);
00076     virtual ~SharedFileCommon() {}
00077 
00078     friend class ecl::SharedFile;
00079     friend class SharedFileManager;
00080 
00081 private:
00082     unsigned int count;
00083     ecl::Mutex mutex;
00084     OFile file;
00085         Error error_handler;
00086 };
00087 
00088 class SharedFileManager {
00089 public:
00090         static SharedFileCommon* RegisterSharedFile(const std::string &name, ecl::WriteMode mode = New) ecl_throw_decl(StandardException);
00091         static bool DeRegisterSharedFile(const std::string &name) ecl_throw_decl(StandardException);
00092 private:
00093         static ecl::Mutex mutex;
00094         static std::map<std::string,SharedFileCommon*> opened_files;
00095 };
00096 
00097 } // namespace devices
00098 
00099 /*****************************************************************************
00100 ** Interface [SharedFile]
00101 *****************************************************************************/
00118 class ecl_devices_PUBLIC SharedFile {
00119 public:
00120         /*********************
00121         ** C&D
00122         **********************/
00130         SharedFile() {};
00144         SharedFile(const std::string &name, WriteMode mode = New) ecl_throw_decl(StandardException);
00150         virtual ~SharedFile();
00151 
00166         bool open(const std::string &name, WriteMode mode = New) ecl_throw_decl(StandardException);
00167 
00168         /*********************
00169         ** Shared File Methods
00170         **********************/
00178         unsigned int count() { return shared_instance->count; }
00179 
00180         /*********************
00181         ** OutputDevice Methods
00182         **********************/
00188         bool open() { return shared_instance->file.open(); }
00203         long write(const char &c) ecl_debug_throw_decl(StandardException);
00219         long write(const char* s, unsigned long n) ecl_debug_throw_decl(StandardException);
00228         bool flush() ecl_debug_throw_decl(StandardException);
00229 
00230         const Error& error() const { return shared_instance->error_handler; }
00231 
00232 private:
00233         devices::SharedFileCommon* shared_instance;
00234         devices::CharBuffer buffer;
00235 };
00236 
00237 /*****************************************************************************
00238 ** Traits [SharedFile]
00239 *****************************************************************************/
00245 template <>
00246 class is_sink<SharedFile> : public True {};
00247 
00248 } // namespace ecl
00249 
00250 #endif /* ECL_DEVICES_SHARED_FILE_HPP_ */


ecl_devices
Author(s): Daniel Stonier
autogenerated on Sun Oct 5 2014 23:35:57