Elm  2
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
Fletcher.h
1 /*
2  * $Id$
3  * Fletcher class interface
4  *
5  * This file is part of OTAWA
6  * Copyright (c) 2007, IRIT UPS.
7  *
8  * OTAWA is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * OTAWA is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with OTAWA; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 #ifndef ELM_CHECKSUM_FLETCHER_H
23 #define ELM_CHECKSUM_FLETCHER_H
24 
25 #include <elm/types.h>
26 #include <elm/io/InStream.h>
27 #include <elm/io/OutStream.h>
28 
29 namespace elm { namespace checksum {
30 
31 // Fletcher class
32 class Fletcher {
33 public:
34  Fletcher(void);
35  virtual ~Fletcher(void);
36  t::uint32 sum(void);
37  void put(io::InStream& in);
38  void put(const void *buffer, int length);
39  void put(const CString& str);
40  void put(const String& str);
41  inline Fletcher& operator<<(const char *str)
42  { put(CString(str)); return *this; }
43  inline Fletcher& operator<<(const CString& str)
44  { put(str); return *this; }
45  inline Fletcher& operator<<(const String& str)
46  { put(str); return *this; }
47  template <class T> inline Fletcher& operator<<(const T& value)
48  { put(&value, sizeof(T)); return *this; }
49 
50  // io::OutStream overload
51  virtual int write(const char *buffer, int size);
52  virtual int flush(void);
53  virtual cstring lastErrorMessage(void);
54 
55 private:
56  t::uint32 sum1, sum2;
57  t::uint32 len;
58  char half[2];
59  t::uint16 size;
60  inline void shuffle(void);
61  inline void add(void);
62 };
63 
64 } } // elm::checksum
65 
66 #endif // ELM_CHECKSUM_FLETCHER_H
67 
elm::checksum::Fletcher::sum
t::uint32 sum(void)
Definition: checksum_Fletcher.cpp:100
elm::checksum::Fletcher::operator<<
Fletcher & operator<<(const char *str)
Definition: Fletcher.h:41
elm::checksum::Fletcher::flush
virtual int flush(void)
Definition: checksum_Fletcher.cpp:150
elm::t::uint16
unsigned short uint16
Definition: arch.h:29
value
elm::checksum::Fletcher::write
virtual int write(const char *buffer, int size)
Definition: checksum_Fletcher.cpp:142
elm::checksum::Fletcher::operator<<
Fletcher & operator<<(const T &value)
Definition: Fletcher.h:47
elm::CString
Definition: CString.h:17
elm::t::in
typename type_info< T >::in_t in
Definition: type_info.h:283
elm::checksum::Fletcher::Fletcher
Fletcher(void)
Definition: checksum_Fletcher.cpp:45
elm::checksum::Fletcher::lastErrorMessage
virtual cstring lastErrorMessage(void)
Definition: checksum_Fletcher.cpp:157
elm::checksum::Fletcher::~Fletcher
virtual ~Fletcher(void)
Definition: checksum_Fletcher.cpp:164
elm::checksum::Fletcher::operator<<
Fletcher & operator<<(const CString &str)
Definition: Fletcher.h:43
elm
Definition: adapter.h:26
elm::checksum::Fletcher::put
void put(io::InStream &in)
Definition: checksum_Fletcher.cpp:78
elm::t::uint32
unsigned int uint32
Definition: arch.h:31
elm::checksum::Fletcher::operator<<
Fletcher & operator<<(const String &str)
Definition: Fletcher.h:45
elm::String
Definition: String.h:30
elm::checksum::Fletcher
Definition: Fletcher.h:32
elm::str
string str(const char *s)
Definition: String.h:150
elm::io::InStream
Definition: InStream.h:29