Main   Class Hierarchy   Classes   Compound List   Files   Compound Members   File Members   Pages  

util.cpp

Go to the documentation of this file.
00001 //-----------------------------------------------------------------------------
00002 /** @file util.cpp
00003     @see util.h
00004 
00005     $Id: util_8cpp-source.html,v 1.1.1.1 2003/08/07 19:41:39 emarkus Exp $
00006     $Source: /usr/cvsroot/www_pathfind/libpathfind/0.1.0/doc/util_8cpp-source.html,v $
00007 */
00008 //-----------------------------------------------------------------------------
00009 
00010 #include "util.h"
00011 
00012 #include <sstream>
00013 
00014 using namespace std;
00015 using namespace PathFind;
00016 
00017 //-----------------------------------------------------------------------------
00018 
00019 ReadError::ReadError(int line, const string& info)
00020 {
00021     ostringstream s;
00022     s << "Read error line " << line << ": " << info << ends;
00023     setMessage(s.str());
00024 }
00025 
00026 //-----------------------------------------------------------------------------
00027 
00028 LineReader::LineReader(istream& in)
00029     : m_lineNumber(0),
00030       m_in(in)
00031 {
00032 }
00033 
00034 Error LineReader::createError(const string& message)
00035 {
00036     ostringstream out;
00037     out << "Line " << m_lineNumber << ": " << message << ends;
00038     return Error(out.str());
00039 }
00040 
00041 std::string LineReader::readLine()
00042 {
00043     char buffer[MAX_LINE];
00044     m_in.getline(buffer, MAX_LINE);
00045     if (! m_in)
00046         throw Error("Unexpected end of stream.");
00047     ++m_lineNumber;
00048     return string(buffer);
00049 }
00050 
00051 //-----------------------------------------------------------------------------
00052 
00053 char PathFind::getVisitedNodeLabel(int iteration)
00054 {
00055     char label;
00056     if (iteration < 10)
00057         label = ('0' + iteration);
00058     else if (iteration <= 36)
00059         label = ('a' + iteration - 10);
00060     else
00061         label = '+';
00062     return label;
00063 }
00064 
00065 //-----------------------------------------------------------------------------


Generated on Thu Aug 7 13:04:50 2003 by Doxygen1.3.1