当前位置: 首页>>代码示例>>C++>>正文


C++ DataFile::addHeader方法代码示例

本文整理汇总了C++中DataFile::addHeader方法的典型用法代码示例。如果您正苦于以下问题:C++ DataFile::addHeader方法的具体用法?C++ DataFile::addHeader怎么用?C++ DataFile::addHeader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DataFile的用法示例。


在下文中一共展示了DataFile::addHeader方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: addNewHeader

// Add a new header because
// - there's none
// - data type or ctrl_info changed
// - the existing data buffer is full.
// Might switch to new DataFile.
// Will write ctrl_info out if new_ctrl_info is set,
// otherwise the new header tries to point to the existing ctrl_info.
void DataWriter::addNewHeader(bool new_ctrl_info)
{
    FileOffset ctrl_info_offset;
    AutoPtr<DataHeader> new_header;
    {
        bool       new_datafile = false;    // Need to use new DataFile?
        DataFile  *datafile = 0;
        size_t     headroom = 0;
        try
        {
            if (!header)
                new_datafile = true;            // Yes, because there's none.
            else
            {   // Check how big the current data file would get
                FileOffset file_size = header->datafile->getSize();
                headroom = header->datafile->getHeaderSize(channel_name,
                                                           dbr_type, dbr_count,
                                                           next_buffer_size);
                if (new_ctrl_info)
                    headroom += ctrl_info.getSize();
                if (file_size+headroom > file_size_limit) // Yes: reached max. size.
                    new_datafile = true;
            }
            if (new_datafile)
            {
#               ifdef DEBUG_DATA_WRITER
                LOG_MSG("DataWriter::addNewHeader: New Datafile\n");
#               endif
                datafile = createNewDataFile(headroom);
                new_ctrl_info = true;
            }
            else
            {
#               ifdef DEBUG_DATA_WRITER
                LOG_MSG("DataWriter::addNewHeader: adding to '%s'\n",
                        header->datafile->getFilename().c_str());
#               endif
                datafile = header->datafile->reference();
            }
            if (new_ctrl_info)
                datafile->addCtrlInfo(ctrl_info, ctrl_info_offset);
            else // use existing one
                ctrl_info_offset = header->data.ctrl_info_offset;
            new_header = datafile->addHeader(channel_name, dbr_type, dbr_count,
                                             period, next_buffer_size);
            datafile->release(); // now ref'ed by new_header
        }
        catch (GenericException &e)
        {
            if (datafile)
            {
                datafile->release();
                datafile = 0;
            }
            throw GenericException(__FILE__, __LINE__,
                               "Channel '%s':\n%s",
                               channel_name.c_str(), e.what());
        }
    }
    LOG_ASSERT(new_header);
    new_header->data.ctrl_info_offset = ctrl_info_offset;
    if (header)
    {   // Link old header to new one.
        header->set_next(new_header->datafile->getBasename(),
                         new_header->offset);
        header->write();
        // back from new to old.
        new_header->set_prev(header->datafile->getBasename(),
                             header->offset);        
        // Update index entry for the old header.
        if (tree) // Ignore result since block might already be in index
            tree->updateLastDatablock(
                    header->data.begin_time, header->data.end_time,
                    header->offset, header->datafile->getBasename());
    }
    // Switch to new_header (AutoPtr, might del. current header).
    header = new_header;
    // Calc buffer size for the following header (not the current one).
    calc_next_buffer_size(next_buffer_size);
    // new header will be added to index when it's closed.
}
开发者ID:epicsdeb,项目名称:channelarchiver,代码行数:88,代码来源:DataWriter.cpp


注:本文中的DataFile::addHeader方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。