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

Vec3.cc

Go to the documentation of this file.
00001 /*
00002     File:           Vec3.cc
00003 
00004     Function:       Implements Vec3.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/Vec3.h"
00016 #include <ctype.h>
00017 #include <iomanip.h>
00018 
00019 
00020 ostream &operator << (ostream &s, const TVec3 &v)
00021 {
00022     Int w = s.width();
00023 
00024     return(s << '[' << v[0] << ' ' << setw(w) << v[1] << ' ' << setw(w) << v[2] << ']');
00025 }
00026 
00027 istream &operator >> (istream &s, TVec3 &v)
00028 {
00029     TVec3   result;
00030     Char    c;
00031     
00032     // Expected format: [1 2 3]
00033     
00034     while (s >> c && isspace(c))        
00035         ;
00036         
00037     if (c == '[')                       
00038     {
00039         s >> result[0] >> result[1] >> result[2];   
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