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

Vec2.cc

Go to the documentation of this file.
00001 /*
00002     File:           Vec2.cc
00003 
00004     Function:       Implements Vec2.h
00005 
00006     Author(s):      Andrew Willmott
00007 
00008     Copyright:      (c) 1995-2000, Andrew Willmott
00009 
00010     Notes:          
00011 
00012 */
00013 
00014 
00015 #include "vl/Vec2.h"
00016 #include <ctype.h>
00017 #include <iomanip.h>
00018 
00019 
00020 ostream &operator << (ostream &s, const TVec2 &v)
00021 {
00022     Int w = s.width();
00023 
00024     return(s << '[' << v[0] << ' ' << setw(w) << v[1] << ']');
00025 }
00026 
00027 istream &operator >> (istream &s, TVec2 &v)
00028 {
00029     TVec2   result;
00030     Char    c;
00031     
00032     // Expected format: [1 2]
00033     
00034     while (s >> c && isspace(c))        
00035         ;
00036         
00037     if (c == '[')                       
00038     {
00039         s >> result[0] >> result[1];    
00040 
00041         if (!s)
00042         {
00043             cerr << "Error: Expected number while reading vector\n";
00044             return(s);
00045         }
00046             
00047         while (s >> c && isspace(c))
00048             ;
00049             
00050         if (c != ']')
00051         {
00052             s.clear(ios::failbit);
00053             cerr << "Error: Expected ']' while reading vector\n";
00054             return(s);
00055         }
00056     }
00057     else
00058     {
00059         s.clear(ios::failbit);
00060         cerr << "Error: Expected '[' while reading vector\n";
00061         return(s);
00062     }
00063     
00064     v = result;
00065     return(s);
00066 }
00067 

Generated at Sat Aug 5 00:16:49 2000 for Class Library by doxygen 1.1.0 written by Dimitri van Heesch, © 1997-2000