Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

dsBCD.h

Go to the documentation of this file.
00001 /*
00002  * $Id: dsBCD.h,v 1.5 2004/07/21 08:41:46 dsamersoff Exp $
00003  */
00004 #ifndef dsBCD_h
00005 #define dsBCD_h
00006 
00007 #ifdef HAVE_CONFIG_H
00008 #  include <config.h>
00009 #endif
00010 
00011 #include <string.h>
00012 #include <iostream>
00013 
00014 #include <dsSmartException.h>
00015 
00016 DECLARE_EXCEPTION(dsBCD);
00017 
00025 class dsBCD
00026 {
00027     unsigned char _bcd[256];
00028     size_t        _bcd_size;
00029 
00030 public:
00031 
00032 /* Constructors */
00033 
00037   dsBCD(); 
00038 
00042   dsBCD(dsBCD& other);
00043 
00050     dsBCD(long xdec); 
00051 
00059   dsBCD(const char *xdec, size_t size);
00060 
00061 
00062 
00063 /*    Make BCD from decimal     */
00064 
00071     void makeBCD(const char *xdec, size_t xsize);
00072 
00078     void makeBCD(unsigned long xdec);
00079 
00080 
00081 
00082 /*     Read pre-made BCD    */
00083 
00090     void readBCD(const char *ptr, size_t size);
00091 
00099     void readBCD(std::istream& is, size_t bytes = (size_t) -1);
00100 
00101 
00102 
00103 /*    Output constructed BCD    */
00104 
00110     void writeBCD(std::ostream& out);
00111 
00112 
00113 
00114 /* Convert BCD to another representation */
00115 
00121     long toLong();
00122 
00128     void toAscii(std::ostream& out);
00129 
00130 
00131 /*    Accessors       */
00132 
00136     unsigned char *bcd() { return _bcd; }
00137 
00141     int  size(){ return _bcd_size; }
00142 
00143 
00144 };
00145 
00146 inline void dsToBCD(long xdec, std::ostream& out)
00147 {
00148     dsBCD b(xdec);
00149     b.writeBCD(out);
00150 }
00151 
00152 inline void dsToBCD(const char *xdec, std::ostream& out)
00153 {
00154     dsBCD b(xdec, strlen(xdec) );
00155     b.writeBCD(out);
00156 }
00157 
00158 inline long dsFromBCD(const char *ptr, int bytes)
00159 {
00160     dsBCD b;
00161     b.readBCD(ptr, bytes);
00162     return b.toLong();
00163 }
00164 
00165 inline long dsFromBCD(std::istream& is, int bytes)
00166 {
00167     dsBCD b;
00168     b.readBCD(is, bytes);
00169     return b.toLong();
00170 }
00171 
00172 
00173 #endif

Generated on Mon May 16 18:26:57 2005 for libdms4 by doxygen1.3-rc2