From a12bdedce85178f1202d2261dffaba4bcf93a56c Mon Sep 17 00:00:00 2001 From: jiri Date: Wed, 5 Apr 2006 22:06:24 +0000 Subject: [PATCH] *** empty log message *** --- fourindex.h | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/fourindex.h b/fourindex.h index 7b4de1a..b3176ac 100644 --- a/fourindex.h +++ b/fourindex.h @@ -5,6 +5,7 @@ #include #include #include "la.h" +#include "laerror.h" //element of a linked list, indices in a portable way, no bit shifts and endianity problems any more! //note: nn is never compared with individual indices, so indexing from 1 as well as from 0 is possible @@ -170,8 +171,8 @@ public: inline void add(const I (&index)[4], const T elem) {matel4 *ltmp= new matel4; ltmp->next=list; list=ltmp; memcpy(&list->index.packed, &index, sizeof(union packed_index)); list->elem=elem;} - unsigned long put(int fd) const; - unsigned long get(int fd); + unsigned long put(int fd,bool withattr=true) const; + unsigned long get(int fd,bool withattr=true); }; @@ -203,11 +204,13 @@ protected: } void next() { if(current && (unsigned int) (++current - buffer) >=nread) tryread(); } bool eof() {return !current;}; + + public: fourindex_ext(const int file, const fourindexsymtype s=undefined_symmetry, const I n=0, const unsigned int b=256) :current(NULL),fd(file),bufsize(b),nread(0),symmetry(s),nn(n) {buffer = new matel4stored[bufsize]; } ~fourindex_ext() {if(buffer) delete[] buffer;} void setsymmetry(fourindexsymtype s) {symmetry=s;}; - void rewind() {if(0!=lseek(fd,0L,SEEK_SET)) {perror("seek error"); la_error("cannot seek in fourindex_ext");} }; + void rewind() {if(0!=lseek(fd,0L,SEEK_SET)) {perror("seek error"); laerror("cannot seek in fourindex_ext");} }; inline I size() const {return nn;} //iterator and permute-iterator are both implemented as poiters to the original class, using private functions of this class @@ -228,7 +231,7 @@ public: const matel4stored & operator*() const {return *base->current;} bool notNULL() const {return base;} }; - iterator begin() {tryread(); if(!eof()) return this; else return NULL;} + iterator begin() {rewind(); tryread(); if(!eof()) return this; else return NULL;} iterator end() const {return iterator(NULL);} //piterator ... iterate over all allowed permutations; conveniently expressed via the basic iterator which does the block-buffering @@ -275,11 +278,19 @@ public: /////////////////////////////implementations/////////////////////////////////// template -unsigned long fourindex::put(int fd) const +unsigned long fourindex::put(int fd, bool withattr) const { unsigned long n=0; matel4 *l=list; matel4stored buf; +if(withattr) + { + union {fourindexsymtype sym; I n; T padding;} u; + u.sym=symmetry; + if(sizeof(u)!=write(fd,&u,sizeof(u))) laerror("write error in fourindex::put"); + u.n=nn; + if(sizeof(u)!=write(fd,&u,sizeof(u))) laerror("write error in fourindex::put"); + } while(l) { ++n; @@ -293,10 +304,19 @@ return n; template -unsigned long fourindex::get(int fd) +unsigned long fourindex::get(int fd,bool withattr) { unsigned long n=0; matel4stored buf; +if(withattr) + { + union {fourindexsymtype sym; I n; T padding;} u; + if(sizeof(u)!=read(fd,&u,sizeof(u))) laerror("read inconsistency in fourindex::put"); + symmetry=u.sym; + if(sizeof(u)!=read(fd,&u,sizeof(u))) laerror("read inconsistency in fourindex::put"); + nn=u.n; + + } while(sizeof(buf)==read(fd,&buf,sizeof(buf))) {++n; add(buf.index,buf.elem);} return n; }