lid_t.cpp

00001 /*<std-header orig-src='shore'>
00002 
00003  $Id: lid_t.cpp,v 1.38 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 #define LID_T_C
00035 
00036 #ifdef __GNUC__
00037 #pragma implementation
00038 #endif
00039 
00040 #include <cstdlib>
00041 #include <w_stream.h>
00042 #include <cstring>
00043 #include "basics.h"
00044 #include "tid_t.h"
00045 #include "lid_t.h"
00046 
00047 const lvid_t    lvid_t::null;            
00048 
00049 ostream& operator<<(ostream& o, const lvid_t& lvid)
00050 {
00051     const u_char* p = (const u_char*) &lvid.high;
00052     //(char*)inet_ntoa(lvid.net_addr)
00053 
00054         // WARNING: byte-order-dependent
00055     return o << u_int(p[0]) << '.' << u_int(p[1]) << '.'
00056              << u_int(p[2]) << '.' << u_int(p[3]) << ':'
00057              <<        lvid.low;
00058 }
00059 
00060 istream& operator>>(istream& is, lvid_t& lvid)
00061 {
00062     is.clear();
00063     w_base_t::uint4_t i;
00064     char c;
00065     const w_base_t::uint4_t parts = sizeof(lvid.high); // should be 4
00066     int  temp[parts];
00067 
00068     // in case not all fields are represented
00069     // in the input string
00070     for (i=0; i<parts; i++) { temp[i] = 0; }
00071 
00072     // read each part of the lvid "address" and stop if
00073     // it ends early
00074     for (i=0, c='.'; i<parts && c!='\0'; i++) {
00075         is >> temp[i];        
00076         // peek to see the delimiters of lvid pieces.
00077         if (is.peek() == '.' || is.peek()== ':') {
00078             is >> c;
00079         } else {
00080             c = '\0';
00081             break;
00082         }
00083     }
00084     if (i==1) {
00085         // we had a simple integer: put it
00086         // int the low part
00087         lvid.low = temp[0];
00088         temp[0]=0;
00089     } else if (c == ':') {
00090         // we had a.b.c.d:l
00091         // we had a.b.c:l
00092         // we had a.b:l
00093         // we had a:l
00094         if(i!=parts) {
00095             is.clear(ios::badbit);
00096         } else {
00097             is >> lvid.low;
00098         }
00099     } else  {
00100         // we had
00101         // a.b
00102         // a.b.c
00103         // a.b.c.d
00104         is.clear(ios::badbit);
00105     }
00106 
00107     ((char*)&lvid.high)[0] = temp[0];
00108     ((char*)&lvid.high)[1] = temp[1];
00109     ((char*)&lvid.high)[2] = temp[2];
00110     ((char*)&lvid.high)[3] = temp[3];
00111 
00112     return is;
00113 }
00114 
00115 
00116 /* 
00117  * for the benefit of the code that includes
00118  * the structure-only, non-c++ definitions (rpcgen output)
00119  * of  lvid_t 
00120  */
00121 extern "C" bool lvid_t_is_null(const lvid_t &x); 
00122 
00123 bool
00124 lvid_t_is_null(const lvid_t &x)
00125 {
00126       return x == lvid_t::null;
00127 }
00128 

Generated on Wed Jul 7 17:22:32 2010 for Shore Storage Manager by  doxygen 1.4.7