// translate.cc // // Copyright (C) 1997 Limit Point Systems, Inc. // // Author: Curtis Janssen // Maintainer: LPS // // This file is part of the SC Toolkit. // // The SC Toolkit is free software; you can redistribute it and/or modify // it under the terms of the GNU Library General Public License as published by // the Free Software Foundation; either version 2, or (at your option) // any later version. // // The SC Toolkit is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Library General Public License for more details. // // You should have received a copy of the GNU Library General Public License // along with the SC Toolkit; see the file COPYING.LIB. If not, write to // the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. // // The U.S. Government is granted a limited license as per AL 91-7. // #include #include #include using namespace sc; //////////////////////////////////////////////////////////////////////// static inline void swap(char *d, int c1, int c2) { char tmp = d[c1]; d[c1] = d[c2]; d[c2] = tmp; } static inline void swap(char *d, const char *e, int c1, int c2) { d[c1] = e[c2]; d[c2] = e[c1]; } static inline void byte_swap2(char*d) { swap(d,0,1); } static inline void byte_swap2(char*d, const char *e) { swap(d,e,0,1); } static inline void byte_swap4(char*d) { swap(d,0,3); swap(d,1,2); } static inline void byte_swap4(char*d, const char *e) { swap(d,e,0,3); swap(d,e,1,2); } static inline void byte_swap8(char*d) { swap(d,0,7); swap(d,1,6); swap(d,2,5); swap(d,3,4); } static inline void byte_swap8(char*d, const char *e) { swap(d,e,0,7); swap(d,e,1,6); swap(d,e,2,5); swap(d,e,3,4); } static inline void byte_swap16(char*d) { swap(d,0,15); swap(d,1,14); swap(d,2,13); swap(d,3,12); swap(d,4,11); swap(d,5,10); swap(d,6, 9); swap(d,7, 8); } static inline void byte_swap16(char*d, const char *e) { swap(d,e,0,15); swap(d,e,1,14); swap(d,e,2,13); swap(d,e,3,12); swap(d,e,4,11); swap(d,e,5,10); swap(d,e,6, 9); swap(d,e,7, 8); } static inline void byte_swap2(void*data,int n) { char *d = (char*)data; for (int i=0; iput_array_void(d,s); } int TranslateDataOut::put(const char*d,int s) { const int bsize = bufsize; int o=0,r=0; while (s) { int l = (s>bsize?bsize:s); translate_->to_external(buf_,&d[o],l); r += putv(buf_,l); s-=l; o+=l; } return r; } int TranslateDataOut::put(const short*d,int s) { const int bsize = bufsize/sizeof(*d); int o=0,r=0; while (s) { int l = (s>bsize?bsize:s); translate_->to_external(buf_,&d[o],l); r += putv(buf_,l*sizeof(*d)); s-=l; o+=l; } return r; } int TranslateDataOut::put(const unsigned int*d,int s) { const int bsize = bufsize/sizeof(*d); int o=0,r=0; while (s) { int l = (s>bsize?bsize:s); translate_->to_external(buf_,&d[o],l); r += putv(buf_,l*sizeof(*d)); s-=l; o+=l; } return r; } int TranslateDataOut::put(const int*d,int s) { const int bsize = bufsize/sizeof(*d); int o=0,r=0; while (s) { int l = (s>bsize?bsize:s); translate_->to_external(buf_,&d[o],l); r += putv(buf_,l*sizeof(*d)); s-=l; o+=l; } return r; } int TranslateDataOut::put(const long*d,int s) { const int bsize = bufsize/sizeof(*d); int o=0,r=0; while (s) { int l = (s>bsize?bsize:s); translate_->to_external(buf_,&d[o],l); r += putv(buf_,l*sizeof(*d)); s-=l; o+=l; } return r; } int TranslateDataOut::put(const float*d,int s) { const int bsize = bufsize/sizeof(*d); int o=0,r=0; while (s) { int l = (s>bsize?bsize:s); translate_->to_external(buf_,&d[o],l); r += putv(buf_,l*sizeof(*d)); s-=l; o+=l; } return r; } int TranslateDataOut::put(const double*d,int s) { const int bsize = bufsize/sizeof(*d); int o=0,r=0; while (s) { int l = (s>bsize?bsize:s); translate_->to_external(buf_,&d[o],l); r += putv(buf_,l*sizeof(*d)); s-=l; o+=l; } return r; } //////////////////////////////////////////////////////////////////////// TranslateDataIn::TranslateDataIn(StateIn*si,TranslateData *t): si_(si), translate_(t) { } TranslateDataIn::~TranslateDataIn() { delete translate_; } inline int TranslateDataIn::getv(void*d,int s) { return si_->get_array_void(d,s); } int TranslateDataIn::get(char*d,int s) { int r = getv(d,s); translate_->to_native(d,s); return r; } int TranslateDataIn::get(short*d,int s) { int r = getv(d,s*sizeof(short)); translate_->to_native(d,s); return r; } int TranslateDataIn::get(unsigned int*d,int s) { int r = getv(d,s*sizeof(unsigned int)); translate_->to_native(d,s); return r; } int TranslateDataIn::get(int*d,int s) { int r = getv(d,s*sizeof(int)); translate_->to_native(d,s); return r; } int TranslateDataIn::get(long*d,int s) { int r = getv(d,s*sizeof(long)); translate_->to_native(d,s); return r; } int TranslateDataIn::get(float*d,int s) { int r = getv(d,s*sizeof(float)); translate_->to_native(d,s); return r; } int TranslateDataIn::get(double*d,int s) { int r = getv(d,s*sizeof(double)); translate_->to_native(d,s); return r; } //////////////////////////////////////////////////////////////////////// // Local Variables: // mode: c++ // c-file-style: "CLJ" // End: