FACT++  1.0
void Converter::ToFits ( void *  dest,
const void *  src,
size_t  size 
) const
Parameters
destArray to which the destination data is written
srcArray with the source data according to the format stored in the Converter
sizesize of the destination data in bytes

Definition at line 891 of file Converter.cc.

References fFormat, fList, GetSize(), i, and type.

Referenced by GetSize(), ToFits(), and Fits::Write().

892 {
893  // crawl through the src buffer and copy the data appropriately to the
894  // destination buffer
895  // Assumption: the string is always last. This way we
896  // use the provided size to determine the number
897  // of character to copy
898 
899  char *charDest = static_cast<char*>(dest);
900  const char *charSrc = static_cast<const char*>(src);
901 
902  // We skip the last element 'v'
903  for (Converter::FormatList::const_iterator i=fList.begin(); i!=fList.end()-1; i++)
904  {
905  /*
906  // For speed reasons we don't do a check in the loop
907  if (charDest-size>dest || charSrc-size>src)
908  {
909  ostringstream err;
910  err << "Format description [fmt=" << fFormat << "] exceeds available data size (" << size << ")";
911  throw runtime_error(err.str());
912  }
913  */
914 
915  // Skip strings (must be the last, so we could just skip it)
916  const char type = i->first.first->name()[0];
917  if (type=='S')
918  {
919  charSrc += strlen(charSrc)+1;
920  continue;
921  }
922 
923  const int s = i->first.second; // size of element
924  const int n = i->second.first; // number of elements
925 
926  // Check if there are types with unknown sizes
927  if (s==0 || n==0)
928  throw runtime_error(string("Type '")+type+"' not supported converting to FITS.");
929 
930  // Let the compiler do some optimization
931  switch (s)
932  {
933  case 1: memcpy(charDest, charSrc, s*n); charSrc+=s*n; charDest+=s*n; break;
934  case 2: for (int j=0; j<n; j++) { reverse_copy(charSrc, charSrc+2, charDest); charSrc+=2; charDest+=2; } break;
935  case 4: for (int j=0; j<n; j++) { reverse_copy(charSrc, charSrc+4, charDest); charSrc+=4; charDest+=4; } break;
936  case 8: for (int j=0; j<n; j++) { reverse_copy(charSrc, charSrc+8, charDest); charSrc+=8; charDest+=8; } break;
937  }
938  }
939 
940  if (charDest-size!=dest/* || charSrc-size!=src*/)
941  {
942  ostringstream err;
943  err << "ToFits - Data block size (" << size << ") doesn't fit format description [fmt=" << fFormat << "|size=" << GetSize() << "]";
944  throw runtime_error(err.str());
945  }
946 }
int i
Definition: db_dim_client.c:21
int type
int size
Definition: db_dim_server.c:17
const FormatList fList
Original format string.
Definition: Converter.h:33
size_t GetSize() const
Definition: Converter.h:89
const std::string fFormat
ostream to which output is redirected
Definition: Converter.h:32

+ Here is the call graph for this function:

+ Here is the caller graph for this function: