Back to index

nordugrid-arc-nox  1.1.0~rc6
Public Member Functions | Private Attributes
Arc::CRC32Sum Class Reference

Implementation of CRC32 checksum. More...

#include <CheckSum.h>

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

List of all members.

Public Member Functions

 CRC32Sum (void)
virtual ~CRC32Sum (void)
virtual void start (void)
virtual void add (void *buf, unsigned long long int len)
virtual void end (void)
virtual void result (unsigned char *&res, unsigned int &len) const
virtual int print (char *buf, int len) const
virtual void scan (const char *buf)
virtual operator bool (void) const
virtual bool operator! (void) const
uint32_t crc (void) const

Private Attributes

uint32_t r
unsigned long long count
bool computed

Detailed Description

Implementation of CRC32 checksum.

Definition at line 40 of file CheckSum.h.


Constructor & Destructor Documentation

Definition at line 93 of file CheckSum.cpp.

                         {
    start();
  }

Here is the call graph for this function:

virtual Arc::CRC32Sum::~CRC32Sum ( void  ) [inline, virtual]

Definition at line 48 of file CheckSum.h.

{}

Member Function Documentation

void Arc::CRC32Sum::add ( void *  buf,
unsigned long long int  len 
) [virtual]

Implements Arc::CheckSum.

Definition at line 103 of file CheckSum.cpp.

                                                          {
    for (unsigned long long int i = 0; i < len; i++) {
      unsigned char c = (r >> 24);
      r = ((r << 8) | ((unsigned char*)buf)[i]) ^ gtable[c];
    }
    count += len;
  }

Here is the caller graph for this function:

uint32_t Arc::CRC32Sum::crc ( void  ) const [inline]

Definition at line 64 of file CheckSum.h.

                             {
      return r;
    }

Here is the caller graph for this function:

void Arc::CRC32Sum::end ( void  ) [virtual]

Implements Arc::CheckSum.

Definition at line 111 of file CheckSum.cpp.

                         {
    if (computed)
      return;
    unsigned long long l = count;
    for (; l;) {
      unsigned char c = (l & 0xFF);
      ((CheckSum*)this)->add(&c, 1);
      l >>= 8;
    }
    uint32_t u = 0;
    ((CheckSum*)this)->add(&u, 4);
    r = ((~r) & 0xFFFFFFFF);
    computed = true;
  }

Here is the caller graph for this function:

virtual Arc::CRC32Sum::operator bool ( void  ) const [inline, virtual]

Reimplemented from Arc::CheckSum.

Definition at line 58 of file CheckSum.h.

                                      {
      return computed;
    }
virtual bool Arc::CRC32Sum::operator! ( void  ) const [inline, virtual]

Reimplemented from Arc::CheckSum.

Definition at line 61 of file CheckSum.h.

                                       {
      return !computed;
    }
int Arc::CRC32Sum::print ( char *  buf,
int  len 
) const [virtual]

Reimplemented from Arc::CheckSum.

Definition at line 126 of file CheckSum.cpp.

                                              {
    if (!computed) {
      if (len > 0)
        buf[0] = 0;
      return 0;
    }
    return snprintf(buf, len, "cksum: %08x", r);
  }
virtual void Arc::CRC32Sum::result ( unsigned char *&  res,
unsigned int &  len 
) const [inline, virtual]

Implements Arc::CheckSum.

Definition at line 52 of file CheckSum.h.

                                                                      {
      res = (unsigned char*)&r;
      len = 4;
    }
void Arc::CRC32Sum::scan ( const char *  buf) [virtual]

Implements Arc::CheckSum.

Definition at line 135 of file CheckSum.cpp.

                                     {
    computed = false;
    int l;
    if (strncasecmp("cksum:", buf, 6) == 0) {
      unsigned long long rr; // for compatibilty with bug in 0.4
      l = sscanf(buf + 6, "%llx", &rr);
      r = rr;
    }
    else {
      int i;
      l = 0;
      for (i = 0; buf[i]; i++)
        if (!isdigit(buf[i]))
          break;
      if (!(buf[i]))
        l = sscanf(buf, "%u", &r);
      else {
        for (i = 0; buf[i]; i++)
          if (!isxdigit(buf[i]))
            break;
        if (!(buf[i])) {
          unsigned long long rr;
          l = sscanf(buf, "%llx", &rr);
          r = rr;
        }
      }
    }
    if (l != 1)
      return;
    computed = true;
    return;
  }
void Arc::CRC32Sum::start ( void  ) [virtual]

Implements Arc::CheckSum.

Definition at line 97 of file CheckSum.cpp.

                           {
    r = 0;
    count = 0;
    computed = false;
  }

Here is the caller graph for this function:


Member Data Documentation

bool Arc::CRC32Sum::computed [private]

Definition at line 45 of file CheckSum.h.

unsigned long long Arc::CRC32Sum::count [private]

Definition at line 44 of file CheckSum.h.

uint32_t Arc::CRC32Sum::r [private]

Definition at line 43 of file CheckSum.h.


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