Back to index

nordugrid-arc-nox  1.1.0~rc6
Public Types | Public Member Functions | Protected Attributes
Arc::PayloadRaw Class Reference

Raw byte multi-buffer. More...

#include <PayloadRaw.h>

Inheritance diagram for Arc::PayloadRaw:
Inheritance graph
[legend]
Collaboration diagram for Arc::PayloadRaw:
Collaboration graph
[legend]

List of all members.

Public Types

typedef signed long long int Size_t

Public Member Functions

 PayloadRaw (void)
 List of handled buffers.
virtual ~PayloadRaw (void)
 Destructor.
virtual char operator[] (Size_t pos) const
 Returns content of byte at specified position.
virtual char * Content (Size_t pos=-1)
 Get pointer to buffer content at global position 'pos'.
virtual Size_t Size (void) const
 Returns logical size of whole structure.
virtual char * Insert (Size_t pos=0, Size_t size=0)
 Create new buffer at global position 'pos' of size 'size'.
virtual char * Insert (const char *s, Size_t pos=0, Size_t size=-1)
 Create new buffer at global position 'pos' of size 'size'.
virtual char * Buffer (unsigned int num=0)
 Returns pointer to num'th buffer.
virtual Size_t BufferSize (unsigned int num=0) const
 Returns length of num'th buffer.
virtual Size_t BufferPos (unsigned int num=0) const
 Returns position of num'th buffer.
virtual bool Truncate (Size_t size)
 Change size of stored information.

Protected Attributes

Size_t offset_
Size_t size_
std::vector< PayloadRawBufbuf_

Detailed Description

Raw byte multi-buffer.

This is implementation of PayloadRawInterface. Buffers are memory blocks logically placed one after another.

Definition at line 61 of file PayloadRaw.h.


Member Typedef Documentation

typedef signed long long int Arc::PayloadRawInterface::Size_t [inherited]

Definition at line 19 of file PayloadRaw.h.


Constructor & Destructor Documentation

Arc::PayloadRaw::PayloadRaw ( void  ) [inline]

List of handled buffers.

Constructor. Created object contains no buffers.

Definition at line 68 of file PayloadRaw.h.

:offset_(0),size_(0) { };
Arc::PayloadRaw::~PayloadRaw ( void  ) [virtual]

Destructor.

Frees allocated buffers.

Definition at line 12 of file PayloadRaw.cpp.

                            {
  for(std::vector<PayloadRawBuf>::iterator b = buf_.begin();b!=buf_.end();++b) {
    if(b->allocated) free(b->data);
  };
}

Member Function Documentation

char * Arc::PayloadRaw::Buffer ( unsigned int  num = 0) [virtual]

Returns pointer to num'th buffer.

Implements Arc::PayloadRawInterface.

Reimplemented in Arc::PayloadHTTP.

Definition at line 124 of file PayloadRaw.cpp.

                                         {
  if(num>=buf_.size()) return NULL;
  return buf_[num].data;
}

Here is the caller graph for this function:

PayloadRaw::Size_t Arc::PayloadRaw::BufferPos ( unsigned int  num = 0) const [virtual]

Returns position of num'th buffer.

Implements Arc::PayloadRawInterface.

Reimplemented in Arc::PayloadHTTP.

Definition at line 134 of file PayloadRaw.cpp.

                                                             {
  Size_t pos = offset_;
  std::vector<PayloadRawBuf>::const_iterator b = buf_.begin();
  for(;b!=buf_.end();++b) {
    if(!num) break;
    pos+=(b->length);
  };
  return pos;
}

Here is the caller graph for this function:

PayloadRaw::Size_t Arc::PayloadRaw::BufferSize ( unsigned int  num = 0) const [virtual]

Returns length of num'th buffer.

Implements Arc::PayloadRawInterface.

Reimplemented in Arc::PayloadHTTP.

Definition at line 129 of file PayloadRaw.cpp.

                                                              {
  if(num>=buf_.size()) return 0;
  return buf_[num].length;
}
char * Arc::PayloadRaw::Content ( Size_t  pos = -1) [virtual]

Get pointer to buffer content at global position 'pos'.

By default to beginning of main buffer whatever that means.

Implements Arc::PayloadRawInterface.

Reimplemented in Arc::PayloadHTTP.

Definition at line 46 of file PayloadRaw.cpp.

                                    {
  unsigned int bufnum;
  Size_t bufpos;
  if(!BufferAtPos(buf_,pos-offset_,bufnum,bufpos)) return NULL;
  return buf_[bufnum].data+bufpos;
}

Here is the call graph for this function:

Here is the caller graph for this function:

char * Arc::PayloadRaw::Insert ( Size_t  pos = 0,
Size_t  size = 0 
) [virtual]

Create new buffer at global position 'pos' of size 'size'.

Implements Arc::PayloadRawInterface.

Reimplemented in Arc::PayloadHTTP.

Definition at line 69 of file PayloadRaw.cpp.

                                               {
  std::vector<PayloadRawBuf>::iterator bufref;
  Size_t bufpos;
  if(!BufferAtPos(buf_,pos-offset_,bufref,bufpos)) {
    bufref=buf_.end(); bufpos=0;
    if(buf_.size() == 0) {
      offset_=pos;
    } else {
      pos = 0;
      for(unsigned int bufnum = 0;bufnum<buf_.size();bufnum++) {
        pos+=buf_[bufnum].length;
      };
    };
  };
  PayloadRawBuf buf;
  if(bufpos != 0) {
    // Need to split buffers
    buf.size=bufref->length - bufpos;
    buf.data=(char*)malloc(buf.size+1);
    if(!buf.data) return NULL;
    buf.data[buf.size]=0;
    memcpy(buf.data,bufref->data+bufpos,buf.size);
    buf.length=buf.size;
    buf.allocated=true;
    bufref->length=bufpos;
    bufref->data[bufref->length]=0;
    if(bufref->allocated) {
      char* b = (char*)realloc(bufref->data,bufref->length+1);
      if(b) {
        bufref->size=bufref->length;
        bufref->data=b;
      };
    };
    ++bufref;
    bufref=buf_.insert(bufref,buf);
  };
  // Inserting between buffers
  buf.data=(char*)malloc(size+1);
  if(!buf.data) return NULL;
  buf.data[size]=0;
  buf.size=size;
  buf.length=size;
  buf.allocated=true;
  buf_.insert(bufref,buf);
  if((pos+size) > size_) size_=pos+size;
  return buf.data;
}

Here is the call graph for this function:

Here is the caller graph for this function:

char * Arc::PayloadRaw::Insert ( const char *  s,
Size_t  pos = 0,
Size_t  size = -1 
) [virtual]

Create new buffer at global position 'pos' of size 'size'.

Created buffer is filled with content of memory at 's'. If 'size' is negative content at 's' is expected to be null-terminated.

Implements Arc::PayloadRawInterface.

Reimplemented in Arc::PayloadHTTP.

Definition at line 117 of file PayloadRaw.cpp.

                                                             {
  if(size < 0) size=strlen(s);
  char* s_ = Insert(pos,size);
  if(s_) memcpy(s_,s,size);
  return s_;
}

Here is the call graph for this function:

char Arc::PayloadRaw::operator[] ( Size_t  pos) const [virtual]

Returns content of byte at specified position.

Specified position 'pos' is treated as global one and goes through all buffers placed one after another.

Implements Arc::PayloadRawInterface.

Reimplemented in Arc::PayloadHTTP.

Definition at line 53 of file PayloadRaw.cpp.

                                            {
  unsigned int bufnum;
  Size_t bufpos;
  if(!BufferAtPos(buf_,pos-offset_,bufnum,bufpos)) return 0;
  return buf_[bufnum].data[bufpos];
}

Here is the call graph for this function:

PayloadRaw::Size_t Arc::PayloadRaw::Size ( void  ) const [virtual]

Returns logical size of whole structure.

Implements Arc::PayloadRawInterface.

Reimplemented in Arc::PayloadHTTP.

Definition at line 60 of file PayloadRaw.cpp.

                                            {
  return size_;
  //Size_t cpos = 0;
  //for(unsigned int bufnum = 0;bufnum<buf_.size();bufnum++) {
  //  cpos+=buf_[bufnum].length;
  //};
  //return cpos;
}

Here is the caller graph for this function:

bool Arc::PayloadRaw::Truncate ( Size_t  size) [virtual]

Change size of stored information.

If size exceeds end of allocated buffer, buffers are not re-allocated, only logical size is extended. Buffers with location behind new size are deallocated.

Implements Arc::PayloadRawInterface.

Reimplemented in Arc::PayloadHTTP.

Definition at line 144 of file PayloadRaw.cpp.

                                     {
  if(size_ == size) return true; // Buffer is already of right size
  if(size_ < size) { // Buffer needs to be extended
    size_=size; return true;
  };
  if(size <= offset_) {
    // All buffers must be released
    offset_=size;
    for(std::vector<PayloadRawBuf>::iterator b = buf_.begin();b!=buf_.end();) {
      if(b->allocated) free(b->data);
      b=buf_.erase(b);
    };
    size_=size;
    return true;
  };
  Size_t l = offset_;
  for(unsigned int bufnum = 0;bufnum<buf_.size();bufnum++) {
    l+=buf_[bufnum].length;
  };
  if(l == size) {
    size_=size; return true;
  };
  // Buffer must be truncated
  std::vector<PayloadRawBuf>::iterator b;
  Size_t p;
  if(!BufferAtPos(buf_,size-offset_,b,p)) return false;
  if(p != 0) {
    b->length=p; ++b;
  };
  for(;b!=buf_.end();) {
    if(b->allocated) free(b->data);
    b=buf_.erase(b);
  };
  size_=size;
  return true;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

std::vector<PayloadRawBuf> Arc::PayloadRaw::buf_ [protected]

Definition at line 65 of file PayloadRaw.h.

Definition at line 63 of file PayloadRaw.h.

Definition at line 64 of file PayloadRaw.h.


The documentation for this class was generated from the following files: