Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members  

bcarchst.cpp

Go to the documentation of this file.
00001 // $Id$
00002 
00003 //**********************************************************************
00004 //                                                                     *
00005 //    Description:   Concrete derived class for storing and retrieving *
00006 //                   bell code objects to and from a stream archive.   *
00007 //                                                                     *
00008 //    Author:        Chris White (whitecf@bcs.org.uk)                  *
00009 //                                                                     *
00010 //    Copyright (C) 2003  Monitor Computing Services Ltd.              *
00011 //                                                                     *
00012 //    This program is free software; you can redistribute it and/or    *
00013 //    modify it under the terms of the GNU General Public License      *
00014 //    as published by the Free Software Foundation; either version 2   *
00015 //    of the License, or any later version.                            *
00016 //                                                                     *
00017 //    This program is distributed in the hope that it will be useful,  *
00018 //    but WITHOUT ANY WARRANTY; without even the implied warranty of   *
00019 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
00020 //    GNU General Public License for more details.                     *
00021 //                                                                     *
00022 //    You should have received a copy of the GNU General Public        *
00023 //    License (http://www.gnu.org/copyleft/gpl.html) along with this   *
00024 //    program; if not, write to:                                       *
00025 //       The Free Software Foundation Inc.,                            *
00026 //       59 Temple Place - Suite 330,                                  *
00027 //       Boston, MA  02111-1307,                                       *
00028 //       USA.                                                          *
00029 //                                                                     *
00030 //**********************************************************************
00031 //                                                                     *
00032 //    Notes:                                                           *
00033 //                                                                     *
00034 //**********************************************************************
00035 
00036 #include <cstring.h>
00037 #include <iostream.h>
00038 #include <strstrea.h>
00039 
00040 #include "mytrace.h"
00041 
00042 #include "bcarchst.h"
00043 
00044 
00045 using namespace Monitor::BellMaster;
00046 
00047 
00048 
00049 BellCodeArchiveStream::BellCodeArchiveStream(iostream&    newStream) :
00050     BellCodeArchive(), archiveStream(newStream)
00051 {
00052     _USEMYTRACE_("BellCodeArchiveStream::BellCodeArchiveStream()")
00053 }
00054 
00055 
00056 
00057 void
00058 BellCodeArchiveStream::storeDescription(const string&    description)
00059 {
00060     _USEMYTRACE_("BellCodeArchive::storeDescription()")
00061 
00062     archiveStream << description.c_str() << endl;
00063 }
00064 
00065 
00066 
00067 void
00068 BellCodeArchiveStream::storeSequence(const string&    sequence)
00069 {
00070     _USEMYTRACE_("BellCodeArchive::storeSequence()")
00071 
00072     const unsigned char*    charSequence =
00073         (const unsigned char*)sequence.c_str();
00074 
00075     if ('\0' != *charSequence)
00076     {
00077         archiveStream << (unsigned int)*charSequence;
00078         charSequence++;
00079 
00080         while ('\0' != *charSequence)
00081         {
00082             archiveStream << ',' << (unsigned int)*charSequence;
00083             charSequence++;
00084         }
00085     }
00086 
00087     archiveStream << endl;
00088 }
00089 
00090 
00091 
00092 int
00093 BellCodeArchiveStream::retrieveDescription(string&    description)
00094 {
00095     _USEMYTRACE_("BellCodeArchive::retrieveDescription()")
00096 
00097     int    retrieved = !0;
00098 
00099     if (EOF == archiveStream.peek())
00100     {
00101         retrieved = 0;
00102     }
00103     else
00104     {
00105         description.read_line(archiveStream);
00106     }
00107 
00108     return retrieved;
00109 }
00110 
00111 
00112 
00113 int
00114 BellCodeArchiveStream::retrieveSequence(string&    sequence)
00115 {
00116     _USEMYTRACE_("BellCodeArchive::retrieveSequence()")
00117 
00118     int    retrieved = !0;
00119 
00120     if (EOF == archiveStream.peek())
00121     {
00122         retrieved = 0;
00123     }
00124     else
00125     {
00126         strstream    sequenceLine;
00127 
00128         // Get the sequence line into string stream
00129         archiveStream.get(*(sequenceLine.rdbuf()));
00130 
00131         // Get the sequence line as a 'C' string
00132         char    *sequenceStr = sequenceLine.str();
00133 
00134         // Replace any commas with space
00135         char    *commaChar = strrchr(sequenceStr, ',');
00136 
00137         while (commaChar)
00138         {
00139             *commaChar = ' ';
00140             commaChar = strrchr(sequenceStr, ',');
00141         }
00142 
00143         // Read ring values into sequence string
00144         int    ringIndex = 0;
00145 
00146         while (EOF != sequenceLine.peek())
00147         {
00148             unsigned int    rings = 0;
00149             
00150             sequenceLine >> rings;
00151 
00152             sequence.resize(sequence.length() + 1);
00153             sequence[ringIndex] = (unsigned char)rings;
00154             ringIndex++;
00155         }
00156 
00157         sequence.resize(sequence.length() + 1);
00158         sequence[ringIndex] = '\0';
00159     }
00160 
00161     return retrieved;
00162 }

Generated on Wed Oct 29 20:54:52 2003 for Bellmaster BC Common by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002