Scopira 20080306

hexflow.h

00001 
00002 /*
00003  *  Copyright (c) 2002-2007    National Research Council
00004  *
00005  *  All rights reserved.
00006  *
00007  *  This material is confidential and proprietary information of
00008  *  National Research Council Canada ("Confidential Information").
00009  *  This Confidential Information may only be used and reproduced
00010  *  in accordance with the terms of the license agreement.
00011  *
00012  */
00013  
00014 #ifndef __INCLUDED__SCOPIRA_TOO_HEXFLOW__
00015 #define __INCLUDED__SCOPIRA_TOO_HEXFLOW__
00016 
00017 #include <scopira/tool/flow.h>
00018 
00019 namespace scopira
00020 {
00021   namespace tool
00022   {
00023     class hexiflow;
00024     class hexoflow;
00025 
00027     SCOPIRA_EXPORT extern const char* hexchars; // "0123...EF"
00029     SCOPIRA_EXPORT extern const char* lowerhexchars; // "0123...ef"
00030 
00032     inline bool is_hex(char c) {
00033       return
00034         (c >= '0' && c <= '9') ||
00035         (c >= 'a' && c <= 'f') ||
00036         (c >= 'A' && c <= 'F');
00037     }
00038 
00040     inline byte_t char_to_hex(char c) {
00041       // a == 97, A == 65, '0' == 48
00042       // this if-then chain order is important
00043       if (c <= '9')
00044         return c - '0';           // 0..
00045       else if (c <= 'F')
00046         return c - 'A' + 10;      // assume A..
00047       else
00048         return c - 'a' + 10;      // a..
00049     }
00050   }
00051 }
00052 
00058 class scopira::tool::hexiflow : public scopira::tool::iflow_i
00059 {
00060   protected:
00062     count2_ptr< iflow_i > dm_in;
00063 
00064   public:
00072     SCOPIRA_EXPORT hexiflow(bool doref, iflow_i* in);
00073 
00075     SCOPIRA_EXPORT virtual bool failed(void) const;
00076 
00078     SCOPIRA_EXPORT virtual size_t read(byte_t* _buf, size_t _maxsize);
00080     SCOPIRA_EXPORT virtual size_t read_byte(byte_t &out);
00081 
00083     SCOPIRA_EXPORT void open(iflow_i* in);
00085     SCOPIRA_EXPORT void close(void);
00086 };
00087 
00093 class scopira::tool::hexoflow : public scopira::tool::oflow_i
00094 {
00095   protected:
00096     count2_ptr< oflow_i > dm_out;
00097 
00098   public:
00105     SCOPIRA_EXPORT hexoflow(bool doref, oflow_i* out);
00106 
00108     SCOPIRA_EXPORT virtual bool failed(void) const;
00109 
00111     SCOPIRA_EXPORT virtual size_t write(const byte_t* _buf, size_t _size);
00113     SCOPIRA_EXPORT virtual size_t write_byte(byte_t b);
00114 
00116     SCOPIRA_EXPORT void open(oflow_i* in);
00118     SCOPIRA_EXPORT void close(void);
00119 };
00120 
00121 #endif
00122