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


ecl_devices
Author(s): Daniel Stonier (d.stonier@gmail.com)
autogenerated on Thu Jan 2 2014 11:12:50