The Machine Perception Toolbox

[Introduction]- [News]- [Download]- [Screenshots]- [Manual (pdf)]- [Forums]- [API Reference]- [Repository ]

 

Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

io.h

Go to the documentation of this file.
00001 /*
00002  * io.h
00003  *
00004  * Copyright (c) 2003 Machine Perception Laboratory
00005  * University of California San Diego.
00006  * Please read the disclaimer and notes about redistribution
00007  * at the end of this file.
00008  *
00009  * Authors: Josh Susskind
00010  */
00011 #ifndef __MP_WRITER_H__
00012 #define __MP_WRITER_H__
00013 
00014 #include <fstream>
00015 #include "../common.h"
00016 
00017 // =========================================================
00018 
00019 class MPIO
00020 {
00021 public:
00022                 
00023                 MPIO(){};
00024                 ~MPIO(){};
00025         virtual void write(const int &i) = 0;
00026         virtual void write(const double &d) = 0;
00027         virtual void write(const char &ch) = 0;
00028 };
00029 
00030 // =========================================================
00031 
00032 class MPFileIO : public MPIO 
00033 {
00034 private:
00035         std::ofstream os;
00036 
00037 public:
00038         MPFileIO(char *fname) : os(fname, std::ios::app) {};
00039     ~MPFileIO() { os.close(); };
00040 
00041         void write(const int &i);
00042         void write(const double &d);
00043         void write(const char &ch);
00044         void write(const char * s);
00045         void writePGM(float *img, const char *filename, const int &width, const int &height);
00046 };
00047 
00048 // =========================================================
00049 
00050 class MPSocketIO : public MPIO  
00051 {
00052 private:
00053         int _isConnect;
00054         int isConvert;
00055 //      SOCKET clientSock;
00056 //      sockaddr_in cin;
00057         char hostName[40];
00058         int hostPort;
00059         union INT_DATA {
00060                 int data;
00061                 char byte[4];
00062         }int_data;
00063         union FLOAT_DATA {
00064                 float data;
00065                 char byte[4];
00066         }float_data;
00067         union LONG_DATA{
00068                 long data;
00069                 char byte[4];
00070         }long_data;
00071         union DOUBLE_DATE{
00072                 double data;
00073                 char byte[4];
00074         }double_data;
00075         void    writeConvert(char byte[],int numWrite);
00076         int             readConvert(char byte[],int numRead);
00077 
00078 public:
00079         MPSocketIO(char _hostName[],int _hostPort,int _isConvert=FALSE);
00080         virtual ~MPSocketIO();
00081         int             connectServer();
00082         int     isConnect();
00083         void    disconnectServer();
00084         void    writeByte(const char &b);
00085         void    write(const int &i);
00086         void    write(const long &l);
00087         void    write(const char &ch);
00088         void    write(const char *s);
00089         void    write(const float &f);
00090         void    write(const double &d);
00091         char    readByte();
00092         int             readInt();
00093         long    readLong();
00094         float   readFloat();
00095         double  readDouble();
00096         char    readChar();
00097         int             readFull(char bur[],int numRead);
00098 };
00099 
00100 // ================================================================
00101 
00102 #endif __MP_WRITER_H__
00103 
00104 
00105 /*
00106  * 
00107  * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
00108  * 
00109  *    1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
00110  *    2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
00111  *    3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.
00112  * 
00113  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00114  * 
00115  */

Generated on Mon Nov 8 17:07:36 2004 for MPT by  doxygen 1.3.9.1