示例#1
0
//-*****************************************************************************
static void
WriteTimeSamplingType( hid_t iGroup,
                       const std::string &iName,
                       const AbcA::TimeSamplingType &iTimeSamplingType )
{
    const std::string nameSPC = iName + ".tspc";
    const std::string nameTPC = iName + ".ttpc";

    const uint32_t spc = iTimeSamplingType.getNumSamplesPerCycle();
    const chrono_t tpc = iTimeSamplingType.getTimePerCycle();

    if ( iTimeSamplingType.isUniform() )
    {
        // With uniform, we JUST write the time per sample
        assert( spc == 1 );
        WriteScalar( iGroup, nameTPC,
                     H5T_IEEE_F64LE,
                     H5T_NATIVE_DOUBLE,
                     ( const void * )&tpc );
    }
    else if ( iTimeSamplingType.isCyclic() )
    {
        // Here we have to write SPC, and if TPC is 1.0 we don't
        // bother writing it.
        assert( spc > 1 );
        assert( tpc < AbcA::TimeSamplingType::AcyclicTimePerCycle() );
        WriteScalar( iGroup, nameSPC,
                     H5T_STD_U32LE,
                     H5T_NATIVE_UINT32,
                     ( const void * )&spc );
        if ( tpc != 1.0 )
        {
            WriteScalar( iGroup, nameTPC,
                         H5T_IEEE_F64LE,
                         H5T_NATIVE_DOUBLE,
                         ( const void * )&tpc );
        }
    }
    else
    {
        assert( iTimeSamplingType.isAcyclic() );
        assert( spc == AbcA::TimeSamplingType::AcyclicNumSamples() );
        WriteScalar( iGroup, nameSPC,
                     H5T_STD_U32LE,
                     H5T_NATIVE_UINT32,
                     ( const void * )&spc );
    }
}
示例#2
0
uint8_t *ResizeAnyVector(const reflection::Schema &schema, uoffset_t newsize,
                         const VectorOfAny *vec, uoffset_t num_elems,
                         uoffset_t elem_size, std::vector<uint8_t> *flatbuf,
                         const reflection::Object *root_table) {
  auto delta_elem = static_cast<int>(newsize) - static_cast<int>(num_elems);
  auto delta_bytes = delta_elem * static_cast<int>(elem_size);
  auto vec_start = reinterpret_cast<const uint8_t *>(vec) - flatbuf->data();
  auto start = static_cast<uoffset_t>(vec_start + sizeof(uoffset_t) +
                                      elem_size * num_elems);
  if (delta_bytes) {
    if (delta_elem < 0) {
      // Clear elements we're throwing away, since some might remain in the
      // buffer.
      auto size_clear = -delta_elem * elem_size;
      memset(flatbuf->data() + start - size_clear, 0, size_clear);
    }
    ResizeContext(schema, start, delta_bytes, flatbuf, root_table);
    WriteScalar(flatbuf->data() + vec_start, newsize);  // Length field.
    // Set new elements to 0.. this can be overwritten by the caller.
    if (delta_elem > 0) {
      memset(flatbuf->data() + start, 0, delta_elem * elem_size);
    }
  }
  return flatbuf->data() + start;
}
示例#3
0
//-*****************************************************************************
void SpwImpl::copyPreviousSample( hid_t iGroup,
                                  const std::string &iSampleName,
                                  index_t iSampleIndex )
{
    assert( iGroup >= 0 );
    assert( m_previousSample.getData() );
    
    // Write the sample.
    const AbcA::DataType &dtype = m_header->getDataType();
    if ( dtype.getPod() == kStringPOD )
    {
        const std::string *strings
            = reinterpret_cast<const std::string *>(
                m_previousSample.getData() );
        
        if ( dtype.getExtent() == 1 )
        {
            WriteString( iGroup, iSampleName, *strings );
        }
        else
        {
            WriteStrings( iGroup, iSampleName, dtype.getExtent(), strings );
        }
    }
    else if ( dtype.getPod() == kWstringPOD )
    {
        const std::wstring *wstrings
            = reinterpret_cast<const std::wstring *>(
                m_previousSample.getData() );
        
        if ( dtype.getExtent() == 1 )
        {
            WriteWstring( iGroup, iSampleName, *wstrings );
        }
        else
        {
            WriteWstrings( iGroup, iSampleName, dtype.getExtent(), wstrings );
        }
    }
    else
    {
        assert( m_fileDataType >= 0 );
        assert( m_nativeDataType >= 0 );
        WriteScalar( iGroup, iSampleName,
                     m_fileDataType,
                     m_nativeDataType,
                     m_previousSample.getData() );
    }
}