pleyo.com

/src/trunk2/BAL/Tests/TestHelpers/BALFileWriter.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2007 Pleyo.  All rights reserved.
00003  *
00004  * Redistribution and use in source and binary forms, with or without
00005  * modification, are permitted provided that the following conditions
00006  * are met:
00007  *
00008  * 1.  Redistributions of source code must retain the above copyright
00009  *     notice, this list of conditions and the following disclaimer.
00010  * 2.  Redistributions in binary form must reproduce the above copyright
00011  *     notice, this list of conditions and the following disclaimer in the
00012  *     documentation and/or other materials provided with the distribution.
00013  * 3.  Neither the name of Pleyo nor the names of
00014  *     its contributors may be used to endorse or promote products derived
00015  *     from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY PLEYO AND ITS CONTRIBUTORS "AS IS" AND ANY
00018  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00019  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00020  * DISCLAIMED. IN NO EVENT SHALL PLEYO OR ITS CONTRIBUTORS BE LIABLE FOR ANY
00021  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00022  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00023  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00024  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00026  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027  */
00028 #ifndef BALFILE_WRITER_H_
00029 #define BALFILE_WRITER_H_
00030 
00036 #include "stdio.h"
00037 #include <sys/types.h>
00038 #include <sys/stat.h>
00039 
00040 #include "DeprecatedArray.h" // FIXME should diseappear
00041 
00042 namespace BALTest
00043 {
00044 
00045 class BALFileWriter
00046 {
00047 public:
00048         // Constructors opens the file
00049         BALFileWriter( const std::string& );
00050 
00051         // Destructor closes the file if not done already
00052         ~BALFileWriter();
00053 
00054         // Returns the number of bytes read
00055         int Write( const char* aData, int aSize );
00056 
00057   // Closes the file
00058   void Close();
00059   
00060         bool IsOpened() const { return (mStream != NULL); }
00061         
00062         int size() { return m_size; }
00063         
00064 private:
00065         int m_size;
00066   
00067 protected:
00068         FILE *mStream;
00069 };
00070 
00071 inline BALFileWriter::BALFileWriter( const std::string& aName ) : mStream(NULL) {
00072         mStream = fopen(aName.c_str(), "w");
00073         m_size = 0;
00074 }
00075 
00076 inline BALFileWriter::~BALFileWriter()
00077 {
00078   Close();
00079 }
00080 
00081 inline void BALFileWriter::Close()
00082 {
00083         if( mStream ) {
00084                 fclose(mStream);
00085     mStream = NULL;
00086         }
00087 }
00088 
00089 inline int BALFileWriter::Write( const char* aData, int aSize )
00090 {
00091         if(mStream) {
00092             m_size += fwrite( aData, sizeof(char), aSize, mStream );
00093             return m_size;
00094         }
00095         return 0;
00096 }
00097 
00098 }
00099 #endif
00100 

Generated on Wed Nov 21 20:04:17 2007 for Origyn Web Browser by Doxygen 1.5.3

pleyo.com
pleyo.com