Bart Janssens / SVL
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Vec2.cpp Source File

Vec2.cpp

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