Simple Vector Library 1.5 http://www.cs.cmu.edu/~ajw/doc/svl.html

Committer:
BartJanssens
Date:
Tue Jan 05 13:37:50 2016 +0000
Revision:
1:e25ff4b06ed2
Parent:
0:785cff1e5a7c
fixed va_list bug

Who changed what in which revision?

UserRevisionLine numberNew contents of line
BartJanssens 0:785cff1e5a7c 1 /*
BartJanssens 0:785cff1e5a7c 2 File: Vec3.cpp
BartJanssens 0:785cff1e5a7c 3
BartJanssens 0:785cff1e5a7c 4 Function: Implements Vec3.h
BartJanssens 0:785cff1e5a7c 5
BartJanssens 0:785cff1e5a7c 6 Author(s): Andrew Willmott
BartJanssens 0:785cff1e5a7c 7
BartJanssens 0:785cff1e5a7c 8 Copyright: (c) 1995-2001, Andrew Willmott
BartJanssens 0:785cff1e5a7c 9
BartJanssens 0:785cff1e5a7c 10 */
BartJanssens 0:785cff1e5a7c 11
BartJanssens 0:785cff1e5a7c 12
BartJanssens 0:785cff1e5a7c 13 #include "Vec3.h"
BartJanssens 0:785cff1e5a7c 14 //#include <cctype>
BartJanssens 0:785cff1e5a7c 15 //#include <iomanip>
BartJanssens 0:785cff1e5a7c 16
BartJanssens 0:785cff1e5a7c 17 /*
BartJanssens 0:785cff1e5a7c 18 ostream &operator << (ostream &s, const Vec3 &v)
BartJanssens 0:785cff1e5a7c 19 {
BartJanssens 0:785cff1e5a7c 20 Int w = s.width();
BartJanssens 0:785cff1e5a7c 21
BartJanssens 0:785cff1e5a7c 22 return(s << '[' << v[0] << ' ' << setw(w) << v[1] << ' ' << setw(w) << v[2] << ']');
BartJanssens 0:785cff1e5a7c 23 }
BartJanssens 0:785cff1e5a7c 24
BartJanssens 0:785cff1e5a7c 25 istream &operator >> (istream &s, Vec3 &v)
BartJanssens 0:785cff1e5a7c 26 {
BartJanssens 0:785cff1e5a7c 27 Vec3 result;
BartJanssens 0:785cff1e5a7c 28 Char c;
BartJanssens 0:785cff1e5a7c 29
BartJanssens 0:785cff1e5a7c 30 // Expected format: [1 2 3]
BartJanssens 0:785cff1e5a7c 31
BartJanssens 0:785cff1e5a7c 32 while (s >> c && isspace(c))
BartJanssens 0:785cff1e5a7c 33 ;
BartJanssens 0:785cff1e5a7c 34
BartJanssens 0:785cff1e5a7c 35 if (c == '[')
BartJanssens 0:785cff1e5a7c 36 {
BartJanssens 0:785cff1e5a7c 37 s >> result[0] >> result[1] >> result[2];
BartJanssens 0:785cff1e5a7c 38
BartJanssens 0:785cff1e5a7c 39 if (!s)
BartJanssens 0:785cff1e5a7c 40 {
BartJanssens 0:785cff1e5a7c 41 cerr << "Error: Expected number while reading vector\n";
BartJanssens 0:785cff1e5a7c 42 return(s);
BartJanssens 0:785cff1e5a7c 43 }
BartJanssens 0:785cff1e5a7c 44
BartJanssens 0:785cff1e5a7c 45 while (s >> c && isspace(c))
BartJanssens 0:785cff1e5a7c 46 ;
BartJanssens 0:785cff1e5a7c 47
BartJanssens 0:785cff1e5a7c 48 if (c != ']')
BartJanssens 0:785cff1e5a7c 49 {
BartJanssens 0:785cff1e5a7c 50 s.clear(ios::failbit);
BartJanssens 0:785cff1e5a7c 51 cerr << "Error: Expected ']' while reading vector\n";
BartJanssens 0:785cff1e5a7c 52 return(s);
BartJanssens 0:785cff1e5a7c 53 }
BartJanssens 0:785cff1e5a7c 54 }
BartJanssens 0:785cff1e5a7c 55 else
BartJanssens 0:785cff1e5a7c 56 {
BartJanssens 0:785cff1e5a7c 57 s.clear(ios::failbit);
BartJanssens 0:785cff1e5a7c 58 cerr << "Error: Expected '[' while reading vector\n";
BartJanssens 0:785cff1e5a7c 59 return(s);
BartJanssens 0:785cff1e5a7c 60 }
BartJanssens 0:785cff1e5a7c 61
BartJanssens 0:785cff1e5a7c 62 v = result;
BartJanssens 0:785cff1e5a7c 63 return(s);
BartJanssens 0:785cff1e5a7c 64 }
BartJanssens 0:785cff1e5a7c 65 */