Scopira  20080306
hexflow.h
1 
2 /*
3  * Copyright (c) 2002-2007 National Research Council
4  *
5  * All rights reserved.
6  *
7  * This material is confidential and proprietary information of
8  * National Research Council Canada ("Confidential Information").
9  * This Confidential Information may only be used and reproduced
10  * in accordance with the terms of the license agreement.
11  *
12  */
13 
14 #ifndef __INCLUDED__SCOPIRA_TOO_HEXFLOW__
15 #define __INCLUDED__SCOPIRA_TOO_HEXFLOW__
16 
17 #include <scopira/tool/flow.h>
18 
19 namespace scopira
20 {
21  namespace tool
22  {
23  class hexiflow;
24  class hexoflow;
25 
27  SCOPIRA_EXPORT extern const char* hexchars; // "0123...EF"
29  SCOPIRA_EXPORT extern const char* lowerhexchars; // "0123...ef"
30 
32  inline bool is_hex(char c) {
33  return
34  (c >= '0' && c <= '9') ||
35  (c >= 'a' && c <= 'f') ||
36  (c >= 'A' && c <= 'F');
37  }
38 
40  inline byte_t char_to_hex(char c) {
41  // a == 97, A == 65, '0' == 48
42  // this if-then chain order is important
43  if (c <= '9')
44  return c - '0'; // 0..
45  else if (c <= 'F')
46  return c - 'A' + 10; // assume A..
47  else
48  return c - 'a' + 10; // a..
49  }
50  }
51 }
52 
59 {
60  protected:
63 
64  public:
72  SCOPIRA_EXPORT hexiflow(bool doref, iflow_i* in);
73 
75  SCOPIRA_EXPORT virtual bool failed(void) const;
76 
78  SCOPIRA_EXPORT virtual size_t read(byte_t* _buf, size_t _maxsize);
80  SCOPIRA_EXPORT virtual size_t read_byte(byte_t &out);
81 
83  SCOPIRA_EXPORT void open(iflow_i* in);
85  SCOPIRA_EXPORT void close(void);
86 };
87 
94 {
95  protected:
96  count2_ptr< oflow_i > dm_out;
97 
98  public:
105  SCOPIRA_EXPORT hexoflow(bool doref, oflow_i* out);
106 
108  SCOPIRA_EXPORT virtual bool failed(void) const;
109 
111  SCOPIRA_EXPORT virtual size_t write(const byte_t* _buf, size_t _size);
113  SCOPIRA_EXPORT virtual size_t write_byte(byte_t b);
114 
116  SCOPIRA_EXPORT void open(oflow_i* in);
118  SCOPIRA_EXPORT void close(void);
119 };
120 
121 #endif
122 
Definition: flow.h:108
scopira::tool::byte_t byte_t
Definition: flow.h:73
Definition: hexflow.h:93
Definition: archiveflow.h:20
Definition: object.h:43
byte_t char_to_hex(char c)
converts a &#39;0&#39;..&#39;F&#39; (or &#39;0&#39;..&#39;f&#39;) to 0-15
Definition: hexflow.h:40
Definition: hexflow.h:58
hexiflow(bool doref, iflow_i *in)
bool is_hex(char c)
returns true if this is a hex char
Definition: hexflow.h:32
virtual bool failed(void) const
are we in a failed state?
void open(iflow_i *in)
opens a new link
const char * lowerhexchars
array of the 16 digits of hex (lowercase, which you should probably prefer)
const char * hexchars
array of the 16 digits of hex
virtual size_t read(byte_t *_buf, size_t _maxsize)
read raw block data, returns num read in
void close(void)
close the current link
count2_ptr< iflow_i > dm_in
input flow
Definition: hexflow.h:62
virtual size_t read_byte(byte_t &out)
read one byte
Definition: flow.h:159