kvl_t.cpp

00001 /*<std-header orig-src='shore'>
00002 
00003  $Id: kvl_t.cpp,v 1.12 2010/05/26 01:20:12 nhall Exp $
00004 
00005 SHORE -- Scalable Heterogeneous Object REpository
00006 
00007 Copyright (c) 1994-99 Computer Sciences Department, University of
00008                       Wisconsin -- Madison
00009 All Rights Reserved.
00010 
00011 Permission to use, copy, modify and distribute this software and its
00012 documentation is hereby granted, provided that both the copyright
00013 notice and this permission notice appear in all copies of the
00014 software, derivative works or modified versions, and any portions
00015 thereof, and that both notices appear in supporting documentation.
00016 
00017 THE AUTHORS AND THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY
00018 OF WISCONSIN - MADISON ALLOW FREE USE OF THIS SOFTWARE IN ITS
00019 "AS IS" CONDITION, AND THEY DISCLAIM ANY LIABILITY OF ANY KIND
00020 FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
00021 
00022 This software was developed with support by the Advanced Research
00023 Project Agency, ARPA order number 018 (formerly 8230), monitored by
00024 the U.S. Army Research Laboratory under contract DAAB07-91-C-Q518.
00025 Further funding for this work was provided by DARPA through
00026 Rome Research Laboratory Contract No. F30602-97-2-0247.
00027 
00028 */
00029 
00030 #include "w_defines.h"
00031 
00032 /*  -- do not edit anything above this line --   </std-header>*/
00033 
00034 #ifdef __GNUC__
00035 #pragma implementation "kvl_t.h"
00036 #endif
00037 
00038 #define VEC_T_C
00039 #include <cstdlib>
00040 #include <cstring>
00041 #include <w_stream.h>
00042 #include <w_base.h>
00043 #include "basics.h"
00044 #include "kvl_t.h"
00045 
00046 const cvec_t         kvl_t::eof("\0255EOF", 4); // the lexical order doesn't really matter;
00047                                         // it's the likelihood of a user coming up with
00048                                         // this as a legit key that matters
00049 const cvec_t         kvl_t::bof("\0BOF", 4); // not used
00050 
00051 
00052 /*********************************************************************
00053  *
00054  *  operator<<(ostream, kvl)
00055  *
00056  *  Pretty print "kvl" to "ostream".
00057  *
00058  *********************************************************************/
00059 ostream& 
00060 operator<<(ostream& o, const kvl_t& kvl)
00061 {
00062     return o << "k(" << kvl.stid << '.' << kvl.h << '.' << kvl.g << ')';
00063 }
00064 
00065 /*********************************************************************
00066  *
00067  *  operator>>(istream, kvl)
00068  *
00069  *  Read a kvl from istream into "kvl". Format of kvl is a string
00070  *  of format "k(stid.h.g)".
00071  *
00072  *********************************************************************/
00073 istream& 
00074 operator>>(istream& i, kvl_t& kvl)
00075 {
00076     char c[6];
00077     i >> c[0] >> c[1] >> kvl.stid >> c[2]
00078       >> kvl.h >> c[3]
00079       >> kvl.g >> c[4];
00080     c[5] = '\0';
00081     if (i) {
00082         if (strcmp(c, "k(..)"))  {
00083             i.clear(ios::badbit|i.rdstate());  // error
00084         }
00085     }
00086     return i;
00087 }
00088 

Generated on Mon Jan 2 15:13:56 2012 for Shore Storage Manager by  doxygen 1.4.7