InputStream.hpp

Go to the documentation of this file.
00001 /*
00002 SagaEngine library
00003 Copyright (c) 2002-2006 Skalden Studio AS
00004 
00005 This software is provided 'as-is', without any express or implied 
00006 warranty. In no event will the authors be held liable for any 
00007 damages arising from the use of this software.
00008 
00009 Permission is granted to distribute the library under the terms of the 
00010 Q Public License version 1.0. Be sure to read and understand the license
00011 before using the library. It should be included here, or you may read it
00012 at http://www.trolltech.com/products/qt/licenses/licensing/qpl
00013 
00014 The original version of this library can be located at:
00015 http://www.sagaengine.com/
00016 
00017 Rune Myrland
00018 rune@skalden.com
00019 */
00020 
00021 
00022 #ifndef InputStream_hpp
00023 #define InputStream_hpp
00024 
00025 #include "../../util/type/util_type.hpp"
00026 
00027 namespace se_core {
00033     class _SeCoreExport InputStream {
00034     public:
00035         virtual ~InputStream() {}
00036 
00037         virtual unsigned int readHeaderCode() = 0;
00038         virtual unsigned short readLanguageCode() = 0;
00039         virtual int readInt() = 0;
00040         virtual unsigned short readShort() = 0;
00041         virtual float readFloat() = 0;
00042 
00043         virtual unsigned short readDictionaryWord(short dictionaryId) = 0;
00044 
00045         virtual void readLine(char* dest, short maxLen) = 0;
00046         virtual void readLine(String& dest) = 0;
00047         virtual void readString(char* dest, short maxLen) = 0;
00048         virtual void readString(String& dest) = 0;
00049 
00050         virtual int readInfoCode() = 0;
00051         virtual int readPhraseType() = 0;
00052         virtual int readThingType() = 0;
00053 
00054         virtual void readShortArray(ShortArray& dest, int size) = 0;
00055         virtual void readByteArray(ByteArray& dest, int size) = 0;
00056         virtual void readCharArray(String& dest, int size) = 0;
00057 
00058         virtual bool eof() { return true; }
00059 
00060         virtual const char* name() const = 0;
00061 
00062         int nameLen() const {
00063             const char* n = name();
00064             int len = 0;
00065             for(; n[len] != 0; ++len)
00066                 ;
00067             return len;
00068         }
00069 
00070 
00071         int last(char ch, int start = -1) const {
00072             // Find end;
00073             int len = start;
00074             if(len < 0) {
00075                 len = nameLen() - start;
00076             }
00077 
00078             // Find first ch from the end
00079             const char* n = name();
00080             for(int i = len; i > 0; --i) {
00081                 if(n[i] == ch) {
00082                     return i;
00083                 }
00084             }
00085             return -1;
00086         }
00087 
00088 
00089         int basenameLen() const {
00090             int len = nameLen();
00091             int p = last('/', len);
00092             //if(p < 0)
00093             //  return len;
00094             //return len - (p + 1);
00095             // Same but faster. -1 + 1 = 0
00096             return len - (p + 1);
00097         }
00098 
00099 
00100         const char* basename() const {
00101             int len = nameLen();
00102             const char* n = name();
00103             return &n[ len - basenameLen() ];
00104         }
00105 
00106 
00107         const char* oneDirAndBasename() const {
00108             int len = nameLen();
00109             const char* n = name();
00110 
00111             // Find first slash
00112             int p = last('/', len);
00113             if(p <= 0)
00114                 return n;
00115 
00116             // Find second slash
00117             p = last('/', p - 1);
00118             if(p < 0)
00119                 return n;
00120 
00121             return &n[ p + 1 ];
00122         }
00123 
00124 
00125         int extLen() const {
00126             int len = nameLen();
00127 
00128             // Find first dot
00129             int p = last('.', len);
00130 
00131             // No extension?
00132             if(p < 0)
00133                 return 0;
00134 
00135             return len - p;
00136         }
00137 
00138 
00139         const char* ext() const {
00140             int len = nameLen();
00141             const char* n = name();
00142             return &n[ len - extLen() ];
00143         }
00144     };
00145 }
00146 
00147 #endif

Home Page | SagaEngine trunk (updated nightly) reference generated Sun Dec 2 20:06:10 2007 by Doxygen version 1.3.9.1.

SourceForge.net Logo