.. _program_listing_file__tmp_ws_src_ecl_core_ecl_devices_include_ecl_devices_shared_file.hpp: Program Listing for File shared_file.hpp ======================================== |exhale_lsh| :ref:`Return to documentation for file ` (``/tmp/ws/src/ecl_core/ecl_devices/include/ecl/devices/shared_file.hpp``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp /***************************************************************************** ** Ifdefs *****************************************************************************/ #ifndef ECL_DEVICES_SHARED_FILE_HPP_ #define ECL_DEVICES_SHARED_FILE_HPP_ /***************************************************************************** ** Cross Platform Functionality *****************************************************************************/ #include /***************************************************************************** ** Includes *****************************************************************************/ #include #include #include #include #include "detail/character_buffer.hpp" #include "ofile.hpp" #include "traits.hpp" #include "modes.hpp" #include "macros.hpp" /***************************************************************************** ** Namespaces *****************************************************************************/ namespace ecl { /***************************************************************************** ** Forward Definition *****************************************************************************/ class SharedFile; /***************************************************************************** ** Interfaces *****************************************************************************/ namespace devices { /***************************************************************************** ** Interface [SharedFileCommon] *****************************************************************************/ class SharedFileCommon { public: SharedFileCommon() : error_handler(NoError) {}; SharedFileCommon(const std::string &name, ecl::WriteMode mode); virtual ~SharedFileCommon() {} friend class ecl::SharedFile; friend class SharedFileManager; private: unsigned int count; ecl::Mutex mutex; OFile file; Error error_handler; }; class SharedFileManager { public: static SharedFileCommon* RegisterSharedFile(const std::string &name, ecl::WriteMode mode = New); static bool DeRegisterSharedFile(const std::string &name); private: static ecl::Mutex mutex; static std::map opened_files; }; } // namespace devices /***************************************************************************** ** Interface [SharedFile] *****************************************************************************/ class ecl_devices_PUBLIC SharedFile { public: /********************* ** C&D **********************/ SharedFile() {}; SharedFile(const std::string &name, WriteMode mode = New); virtual ~SharedFile(); bool open(const std::string &name, WriteMode mode = New); /********************* ** Shared File Methods **********************/ unsigned int count() { return shared_instance->count; } /********************* ** OutputDevice Methods **********************/ bool open() { return shared_instance->file.open(); } long write(const char &c); long write(const char* s, unsigned long n); bool flush(); const Error& error() const { return shared_instance->error_handler; } private: devices::SharedFileCommon* shared_instance; devices::CharBuffer buffer; }; /***************************************************************************** ** Traits [SharedFile] *****************************************************************************/ template <> class is_sink : public True {}; } // namespace ecl #endif /* ECL_DEVICES_SHARED_FILE_HPP_ */