00001 #ifndef EDG_WORKLOAD_COMMON_UTILITIES_FSTREAMLOCK_H
00002 #define EDG_WORKLOAD_COMMON_UTILITIES_FSTREAMLOCK_H
00003
00004 #include <fstream>
00005
00006 #include "edg/workload/common/common_namespace.h"
00007
00008 COMMON_NAMESPACE_BEGIN {
00009
00010 namespace utilities {
00011
00012 class DescriptorLock {
00013 public:
00014 DescriptorLock( int fd, bool lock = true );
00015
00016 ~DescriptorLock( void );
00017
00018 int lock( void );
00019 int unlock( void );
00020
00021 inline bool locked( void ) { return( this->dl_locked ); }
00022
00023 protected:
00024 bool dl_locked;
00025 int dl_fd;
00026 };
00027
00028 class FstreamLock : public DescriptorLock {
00029 public:
00030 FstreamLock( const std::fstream &fs, bool lock = true );
00031 FstreamLock( const std::ifstream &ifs, bool lock = true );
00032 FstreamLock( const std::ofstream &ofs, bool lock = true );
00033 FstreamLock( const std::filebuf &fb, bool lock = true );
00034
00035 ~FstreamLock( void );
00036
00037 inline int descriptor( void ) { return( this->dl_fd ); }
00038 };
00039
00040 };
00041
00042 } COMMON_NAMESPACE_END;
00043
00044 #endif
00045
00046
00047
00048