| [3420] | 1 | #include "vfs.h" | 
|---|
|  | 2 | #include "pexceptions.h" | 
|---|
|  | 3 | #include "fiondblock.h"  // To use NDataBlock PPF services | 
|---|
|  | 4 |  | 
|---|
|  | 5 | /* Vfs class constructor */ | 
|---|
|  | 6 | Vfs::Vfs(int sz) | 
|---|
|  | 7 | : mFVal(sz) | 
|---|
|  | 8 | { | 
|---|
|  | 9 | for(int k=0; k<sz; k++) | 
|---|
|  | 10 | mSVal.push_back(""); | 
|---|
|  | 11 | } | 
|---|
|  | 12 |  | 
|---|
|  | 13 | void Vfs::Set(int k, r_4 fv, string const  sv) | 
|---|
|  | 14 | { | 
|---|
|  | 15 | if ((k < 0) || (k>= (int)mFVal.Size())) | 
|---|
|  | 16 | throw SOPHYA::RangeCheckError("Vfs::Set() Out of range index!"); | 
|---|
|  | 17 | mFVal(k) = fv; | 
|---|
|  | 18 | mSVal[k] = sv; | 
|---|
|  | 19 | } | 
|---|
|  | 20 |  | 
|---|
|  | 21 | r_4 Vfs::GetF(int k) | 
|---|
|  | 22 | { | 
|---|
|  | 23 | if ((k < 0) || (k>= (int)mFVal.Size())) | 
|---|
|  | 24 | throw SOPHYA::RangeCheckError("Vfs::GetF() Out of range index!"); | 
|---|
|  | 25 | return mFVal(k); | 
|---|
|  | 26 | } | 
|---|
|  | 27 |  | 
|---|
|  | 28 | string Vfs::GetS(int k) | 
|---|
|  | 29 | { | 
|---|
|  | 30 | if ((k < 0) || (k>= (int)mFVal.Size())) | 
|---|
|  | 31 | throw SOPHYA::RangeCheckError("Vfs::GetS() Out of range index!"); | 
|---|
|  | 32 | return mSVal[k]; | 
|---|
|  | 33 | } | 
|---|
|  | 34 |  | 
|---|
|  | 35 | void Vfs::Print(ostream& os) const | 
|---|
|  | 36 | { | 
|---|
|  | 37 | os << "Vfs::Print() - Size= " << mFVal.Size() << endl; | 
|---|
|  | 38 | for(int k=0; k<(int)mFVal.Size(); k++) | 
|---|
|  | 39 | os << "K=" << k << " FVal= " << mFVal(k) << " SVal=" << mSVal[k] << endl; | 
|---|
|  | 40 | os << endl; | 
|---|
|  | 41 | } | 
|---|
|  | 42 |  | 
|---|
|  | 43 | //----------------------------------------------------------------------- | 
|---|
|  | 44 | //  The PPF handler : ObjFileIO<T> is in namespace SOPHYA , | 
|---|
|  | 45 | //  We declare ObjFileIO<Vfs> in the SOPHYA namespace ... | 
|---|
|  | 46 | //  Only, the WriteSelf() and ReadSelf() methods have to be provided | 
|---|
|  | 47 | //----------------------------------------------------------------------- | 
|---|
|  | 48 |  | 
|---|
|  | 49 | namespace SOPHYA { | 
|---|
|  | 50 |  | 
|---|
|  | 51 | DECL_TEMP_SPEC  /* equivalent a template <> , pour SGI-CC en particulier */ | 
|---|
|  | 52 | void ObjFileIO<Vfs>::WriteSelf(POutPersist& s) const | 
|---|
|  | 53 | { | 
|---|
|  | 54 | //  On ecrit 2 uint_4 .... | 
|---|
|  | 55 | //  0: Numero de version,  2 : reserve | 
|---|
|  | 56 | uint_4 itab[2]; | 
|---|
|  | 57 | itab[0] = 1;  // Numero de version a 1 | 
|---|
|  | 58 | itab[1] = 0;  // Reserved for future use | 
|---|
|  | 59 | s.Put(itab, 2); | 
|---|
|  | 60 | s << dobj->mFVal;  // We write the float data block | 
|---|
|  | 61 | // We write now the string vector , as a series of strings | 
|---|
|  | 62 | for(int k=0; k<(int)dobj->mFVal.Size(); k++) | 
|---|
|  | 63 | s.PutStr(dobj->mSVal[k]); | 
|---|
|  | 64 | } | 
|---|
|  | 65 |  | 
|---|
|  | 66 | DECL_TEMP_SPEC  /* equivalent a template <> , pour SGI-CC en particulier */ | 
|---|
|  | 67 | void ObjFileIO<Vfs>::ReadSelf(PInPersist& s) | 
|---|
|  | 68 | { | 
|---|
|  | 69 | // We read in the same order as the write | 
|---|
|  | 70 | // First the two integer containing the version numer | 
|---|
|  | 71 | uint_4 itab[2]; | 
|---|
|  | 72 | s.Get(itab, 2); | 
|---|
|  | 73 | // next, we read in the float data vector | 
|---|
|  | 74 | s >> dobj->mFVal; | 
|---|
|  | 75 | // We resest the  vector<string> dobj->mSVal | 
|---|
|  | 76 | dobj->mSVal.clear(); | 
|---|
|  | 77 | // We read in the mFVal.Size() and keep them in dobj->mSVal | 
|---|
|  | 78 | string buff; | 
|---|
|  | 79 | for(int k=0; k<(int)dobj->mFVal.Size(); k++) { | 
|---|
|  | 80 | s.GetStr(buff); | 
|---|
|  | 81 | dobj->mSVal.push_back(buff); | 
|---|
|  | 82 | } | 
|---|
|  | 83 | } | 
|---|
|  | 84 |  | 
|---|
|  | 85 | // We force the instanciation of the template class ObjFileIO<Vfs> | 
|---|
|  | 86 | #ifdef __CXX_PRAGMA_TEMPLATES__ | 
|---|
|  | 87 | #pragma define_template ObjFileIO<Vfs> | 
|---|
|  | 88 | #endif | 
|---|
|  | 89 |  | 
|---|
|  | 90 | #if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES) | 
|---|
|  | 91 | template class ObjFileIO<Vfs>; | 
|---|
|  | 92 | #endif | 
|---|
|  | 93 |  | 
|---|
|  | 94 | } // End of namespace SOPHYA | 
|---|
|  | 95 |  | 
|---|