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

littleendian_strings.cxx

Go to the documentation of this file.
00001 #include <cstring>
00002 #include "Rtypes.h"
00003 #include "RawData/littleendian_strings.h"
00004 
00005 //____________________________________________________________________________
00006 
00007 UInt_t nwords_in_string(const Char_t* x) {
00008    // add 1 for \0, pad up to the next Int_t
00009    UInt_t csize = strlen(x);
00010    return ((csize+1)+(sizeof(Int_t)-1))/sizeof(Int_t);
00011 }
00012 
00013 //____________________________________________________________________________
00014 void pack_string_in_lel(Int_t* dest_i ,const Char_t* src_c) {
00015    // Put string in an array of little endian long words (32 bit)
00016    // pad out to full word as necessary
00017    // Assume destination has sufficient space
00018 
00019    UInt_t nchar = strlen(src_c);
00020    UInt_t nwd   = nwords_in_string(src_c);
00021 
00022    Char_t* dest_c = (Char_t*) dest_i;
00023 
00024    dest_i[nwd-1] = 0;           // pad out last full word to zeros
00025    memcpy(dest_c,src_c,nchar);  // copy up to '\0'
00026 
00027    // byte swap as necessary to get little endian ordering
00028    for (UInt_t i=0; i<nwd; ++i) 
00029       dest_i[i] = (Int_t)minos_htolel((UInt_t)dest_i[i]);
00030 }
00031 
00032 //____________________________________________________________________________
00033 Char_t* unpack_lel_to_string(const Int_t* src_i, UInt_t nwd) {
00034    // return the string that is packed into an array of little endian
00035    // long words (32 bit)
00036    // NOTE: the user is responsible for deleting this memory
00037   
00038    const UInt_t cperl = sizeof(Int_t)/sizeof(Char_t);
00039 
00040    UInt_t nchar = nwd*cperl;
00041 
00042    Char_t* dest_c = new Char_t [nchar];
00043    Int_t*  dest_i = (Int_t*) dest_c;
00044    const Char_t* src_c  = (const Char_t*) src_i;
00045    memcpy(dest_c,src_c,nchar);
00046 
00047    // byte swap as necessary to deal with original little endian-ness
00048    for (UInt_t i=0; i<nwd; ++i) 
00049       dest_i[i] = (Int_t)minos_letohl((UInt_t)dest_i[i]);
00050 
00051    return dest_c;
00052 }

Generated on Mon Feb 15 11:06:53 2010 for loon by  doxygen 1.3.9.1