Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members | Related Pages | Examples

vos/metaobjects/property/fileproperty.hh

Go to the documentation of this file.
00001 /*
00002     This file is part of the Virtual Object System of
00003     the Interreality project (http://interreality.org).
00004 
00005     Copyright (C) 2001, 2002, 2003 Peter Amstutz
00006 
00007     This library is free software; you can redistribute it and/or
00008     modify it under the terms of the GNU Lesser General Public
00009     License as published by the Free Software Foundation; either
00010     version 2 of the License, or (at your option) any later version.
00011 
00012     This library is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015     Lesser General Public License for more details.
00016 
00017     You should have received a copy of the GNU Lesser General Public
00018     License along with this library; if not, write to the Free Software
00019     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
00020 
00021     Peter Amstutz <tetron@interreality.org>
00022 */
00023 #ifndef _FILEPROPERTY_HH_
00024 #define _FILEPROPERTY_HH_
00025 
00026 #include "property.hh"
00027 #include <sys/types.h>
00028 #include <sys/stat.h>
00029 
00030 /**  @class FileProperty fileproperty.hh vos/metaobjects/property/fileproperty.hh
00031  *
00032  * A subclass of LocalProperty that uses a file as the backing store of the
00033  * property data.  All changes to this property will be reflected in
00034  * the file (so be careful with access control!), and any changes to the file
00035  * will be seen in the property data.
00036  * Use setFileBackend() to set the filename and datatype.
00037  */
00038 
00039 class PROPERTY_API FileProperty : public virtual LocalProperty
00040 {
00041 public:
00042     class FileAccessError : public runtime_error {
00043     public:
00044         FileAccessError(const string& s) : runtime_error(s) { };
00045     };
00046 
00047 private:
00048     FILE* filehandle;
00049     string filename;
00050     struct stat status;
00051     bool readonly;
00052     void checkOpenFile() throw (FileAccessError);
00053 
00054 public:
00055     /** @internal */
00056     FileProperty(MetaObject* superobject);
00057 
00058     /** @internal */
00059     FileProperty(MetaObject* superobject, const string& filename, const string& datatype = "?");
00060 
00061     ~FileProperty();
00062 
00063     /** Register extender with factoory. You should also call Property::registerExtenders(). */
00064     static void registerExtenders();
00065 
00066     /** @internal */
00067     static MetaObject* new_FileProperty(MetaObject* superobject, const string& type);
00068 
00069     /** Open a file and start using it as the backend store for the property.
00070       * @throw FileAccessError If there was an error opening the file.
00071       */
00072     virtual void setFileBackend(const string& filename, const string& filetype = "?") throw(FileAccessError);
00073 
00074     /** Get filename string */
00075     virtual string getFileBackend();
00076 
00077     virtual int getRawLength() throw(FileAccessError);
00078     virtual void readRaw(string& target, int start, int length) throw(FileAccessError);
00079     virtual void read(string& target, int start, int length) throw(FileAccessError) ;
00080     virtual void write(int start, const string& newdata) throw(FileAccessError);
00081     virtual void replace(const string& newdata, const string& newtype = "?") throw(FileAccessError);
00082 };
00083 
00084 #endif

Generated on Tue Aug 12 03:55:45 2003 for Interreality Project - VOS by doxygen 1.3.2