// -*- C++ -*- // $RCSfile: enumio.C,v $ // $Revision: 1.4 $ // $Author: langer $ // $Date: 2000/09/06 20:11:30 $ /* This software was produced by NIST, an agency of the U.S. government, * and by statute is not subject to copyright in the United States. * Recipients of this software assume all responsibilities associated * with its operation, modification and maintenance. However, to * facilitate maintenance we ask that before distributing modifed * versions of this software, you first contact the authors at * oof_manager@ctcms.nist.gov. */ #ifndef ENUMIO_C #define ENUMIO_C #include #include #include "enum.h" #include "word.h" #include "menuDef.h" #include "readbinary.h" template ostream &operator<<(ostream &os, const Enum &e) { assert(e.x < e.names().capacity()); os << *e.names()[e.x]; return os; } template istream &operator>>(istream &is, Enum &e) { Word name; Vec &namelist = e.names(); int i; is >> name; // look for exact match for(i=0; i 1) break; which = i; } } if(nfound == 1) { e.x = (ENUMTYPE) which; return is; } is.clear(ios::badbit|is.rdstate()); garcon()->msout << ms_error << "Bad name (" << name << ") for enumerated type!" << endl; garcon()->msout << "Choices are:"; for(i=0; imsout << " " << *namelist[i]; garcon()->msout << endl << ms_normal; return is; } template void writebinary(FILE *file, const Enum &x, const int n) { // Write Enums as null terminated strings. Writing them as ints // isn't necessarily portable. const Enum *p = &x; for(int i=0; i int readbinary(FILE *file, Enum &x, const int n) { Enum *p = &x; for(int i=0; i> p[i]; if(!is) return i; } return n; } #endif