Back to index

nordugrid-arc-nox  1.1.0~rc6
PayloadFile.h
Go to the documentation of this file.
00001 #ifndef __ARC_PAYLOADFILE_H__
00002 #define __ARC_PAYLOADFILE_H__
00003 
00004 #include <vector>
00005 
00006 #include <arc/message/PayloadRaw.h>
00007 #include <arc/message/PayloadStream.h>
00008 
00009 namespace Hopi {
00010 
00013 class PayloadFile: public Arc::PayloadRawInterface {
00014  protected:
00015   /* TODO: use system-independent file access */
00016   int handle_;
00017   char* addr_;
00018   size_t size_; 
00019   size_t start_; 
00020   size_t end_; 
00021  public:
00024   PayloadFile(const char* filename,Size_t start,Size_t end);
00027   //PayloadFile(const char* filename,Size_t size);
00028   virtual ~PayloadFile(void);
00029   virtual char operator[](Size_t pos) const;
00030   virtual char* Content(Size_t pos = -1);
00031   virtual Size_t Size(void) const;
00032   virtual char* Insert(Size_t pos = 0,Size_t size = 0);
00033   virtual char* Insert(const char* s,Size_t pos = 0,Size_t size = -1);
00034   virtual char* Buffer(unsigned int num);
00035   virtual Size_t BufferSize(unsigned int num) const;
00036   virtual Size_t BufferPos(unsigned int num) const;
00037   virtual bool Truncate(Size_t size);
00038 
00039   operator bool(void) { return (handle_ != -1); };
00040   bool operator!(void) { return (handle_ == -1); };
00041 };
00042 
00043 class PayloadBigFile: public Arc::PayloadStream {
00044  private:
00045   static Size_t threshold_;
00046   size_t limit_; 
00047  public:
00049   PayloadBigFile(const char* filename,Size_t start,Size_t end);
00052   //PayloadBigFile(const char* filename,Size_t size);
00053   virtual ~PayloadBigFile(void);
00054   virtual Size_t Pos(void) const;
00055   virtual Size_t Size(void) const;
00056   virtual Size_t Limit(void) const;
00057   virtual bool Get(char* buf,int& size);
00058 
00059   operator bool(void) { return (handle_ != -1); };
00060   bool operator!(void) { return (handle_ == -1); };
00061   static Size_t Threshold(void) { return threshold_; };
00062   static void Threshold(Size_t t) { if(t > 0) threshold_=t; };
00063 };
00064 
00065 Arc::MessagePayload* newFileRead(const char* filename,Arc::PayloadRawInterface::Size_t start = 0,Arc::PayloadRawInterface::Size_t end = (Arc::PayloadRawInterface::Size_t)(-1));
00066 
00067 } // namespace Hopi
00068 
00069 #endif /* __ARC_PAYLOADFILE_H__ */