proj home

Files   Classes   Functions   Hierarchy  

asciitodig Class Reference

Convert a stream to a string of ASCII digits. More...

#include <streamconversion.h>

List of all members.

Static Public Member Functions

static void forward (string &os, istream &is)
 Convert a stream to a string of ascii digits.
static void reverse (ostream &os, string const &in)
 Convert a string of ascii digits to a stream.


Detailed Description

Convert a stream to a string of ASCII digits.

Definition at line 14 of file streamconversion.h.


Member Function Documentation

void asciitodig::forward ( string &  os,
istream &  is 
) [static]

Convert a stream to a string of ascii digits.

Definition at line 13 of file streamconversion.cpp.

Referenced by rsatest::test01().

00014 {
00015   char ch;
00016   uint w;
00017   is.unsetf(ios::skipws);
00018   while (is.eof()==false)
00019   {
00020     is >> ch;
00021     if (is.eof())
00022       break;
00023     w = (uint)ch;
00024   
00025     stringstream ss;
00026     if (w==0)
00027       ss << "000";
00028     else
00029     if (w<10)
00030       ss << "00" << w;
00031     else
00032     if (w<100)
00033       ss << "0" << w;
00034     else
00035       ss << w;
00036 
00037     os += ss.str();
00038   }
00039 }

void asciitodig::reverse ( ostream os,
string const &  in 
) [static]

Convert a string of ascii digits to a stream.

Definition at line 42 of file streamconversion.cpp.

Referenced by rsatest::test01().

00046 {
00047   assert((in.size()%3)==0);
00048   uintc n = in.size()/3;
00049 
00050   string s;
00051   char c;
00052   uint x;
00053   for (uint k=0; k<n; ++k) 
00054   {
00055     s = in.substr(3*k,3);
00056     stringstream ss(s.c_str());
00057     ss >> x;
00058     c = (char)x;
00059     os << c;
00060   }
00061 }


The documentation for this class was generated from the following files:

Generated on Fri Mar 4 00:49:50 2011 for Chelton Evans Source by  doxygen 1.5.8