Elm  1.0
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
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 
Fletcher & operator<<(const CString &str)
Definition: Fletcher.h:43
Definition: CString.h:17
Fletcher & operator<<(const String &str)
Definition: Fletcher.h:45
virtual int flush(void)
Definition: checksum_Fletcher.cpp:148
Fletcher(void)
Definition: checksum_Fletcher.cpp:43
t::uint32 sum(void)
Definition: checksum_Fletcher.cpp:98
sys::SystemInStream & in
Definition: system_SystemIO.cpp:95
Fletcher & operator<<(const T &value)
Definition: Fletcher.h:47
virtual ~Fletcher(void)
Definition: checksum_Fletcher.cpp:162
Fletcher & operator<<(const char *str)
Definition: Fletcher.h:41
value_t value(CString name, int value)
Definition: rtti.h:40
virtual int write(const char *buffer, int size)
Definition: checksum_Fletcher.cpp:140
Definition: Fletcher.h:32
Definition: String.h:31
void put(io::InStream &in)
Definition: checksum_Fletcher.cpp:76
Definition: InStream.h:30
uint16_t uint16
Definition: int.h:33
uint32_t uint32
Definition: int.h:35
virtual cstring lastErrorMessage(void)
Definition: checksum_Fletcher.cpp:155