/* * Copyright (c) 1996 Gunther Schadow. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #pragma interface #include #include #include #include #include #include class Xdr: public XDR { public: enum op_t { op_nocode = -1, op_encode = XDR_ENCODE, op_decode = XDR_DECODE, op_free = XDR_FREE, }; typedef bool_t (*codef_t)(XDR*, void *); Xdr(int fd, op_t op = op_nocode); Xdr(streambuf*, op_t op = op_nocode); virtual ~Xdr(); void flush(); void encode(); void decode(); void nocode(); void free(); bool code(void); bool code(bool&); bool code(char&); bool code(short&); bool code(u_short&); bool code(int&); bool code(u_int&); bool code(long&); bool code(u_long&); bool code(float&); bool code(double&); bool code(char*&); // a XDR `string *' because char* can be NULL bool code_string (char* &, size_t max = UINT_MAX); bool code_bytes (void *&, size_t &size, size_t max = UINT_MAX); bool code_opaque (void *, size_t size); bool code_reference(void *&, size_t size, codef_t); bool code_pointer (void *&, size_t size, codef_t); bool code_vector (void * , size_t size, codef_t, u_int cnt); bool code_array (void *&, size_t size, codef_t, u_int &cnt, u_int max = UINT_MAX); # define CODEF(T) static bool \ codef(Xdr *x, T *p) { if(p==NULL) p = new Foo; return p->code(*x); } # define CODEFV(T) static bool \ codef_vector(Xdr &x, T *p, u_int cnt) \ { return x.code_vector(p, sizeof(T), (Xdr::codef_t)T::codef, cnt); } # define CODEFA(T) static bool \ codef_array(Xdr &x, T *&p, u_int cnt, u_int max = UINT_MAX) \ { return x.code_array((void *&)p, sizeof(T), (Xdr::codef_t)T::codef, \ cnt, max); } # define CODEF_ALL(T) CODEF(T) CODEFV(T) CODEFA(T) }; #ifndef OUTLINE #include "Xdr.icc" #endif