C++11 如何与xerces-c一起使用锁

C++11 如何与xerces-c一起使用锁,c++11,ubuntu,xerces-c,lockfile,C++11,Ubuntu,Xerces C,Lockfile,我是编程新手,我正在尝试使用lockf来锁定XML文件。我使用xerces-c解析XML文件,需要锁定该文件。该功能与下面的示例类似: void GetConfig::readConfigFile(string& configFile) throw( std::runtime_error ) { // Configure DOM parser. m_ConfigFileParser->setValidationScheme( XercesDOMPars

我是编程新手,我正在尝试使用lockf来锁定XML文件。我使用xerces-c解析XML文件,需要锁定该文件。该功能与下面的示例类似:

void GetConfig::readConfigFile(string& configFile)
        throw( std::runtime_error )
{
   // Configure DOM parser.

   m_ConfigFileParser->setValidationScheme( XercesDOMParser::Val_Never );
   m_ConfigFileParser->setDoNamespaces( false );
   m_ConfigFileParser->setDoSchema( false );
   m_ConfigFileParser->setLoadExternalDTD( false );

   try
   {
      m_ConfigFileParser->parse( configFile.c_str() );

      // no need to free this pointer - owned by the parent parser object
      DOMDocument* xmlDoc = m_ConfigFileParser->getDocument();

      // Get the top-level element: NAme is "root". No attributes for "root"

      DOMElement* elementRoot = xmlDoc->getDocumentElement();
      if( !elementRoot ) throw(std::runtime_error( "empty XML document" ));

      // Parse XML file for tags of interest: "ApplicationSettings"
      // Look one level nested within "root". (child of root)

      DOMNodeList*      children = elementRoot->getChildNodes();
      const  XMLSize_t nodeCount = children->getLength();

      // For all nodes, children of "root" in the XML tree.

      for( XMLSize_t xx = 0; xx < nodeCount; ++xx )
      {
         DOMNode* currentNode = children->item(xx);
         if( currentNode->getNodeType() &&  // true is not NULL
         currentNode->getNodeType() == DOMNode::ELEMENT_NODE ) // is element
         {
        // Found node which is an Element. Re-cast node as element
            DOMElement* currentElement
                    = dynamic_cast< xercesc::DOMElement* >( currentNode );
            if( XMLString::equals(currentElement->getTagName(), TAG_ApplicationSettings))
            {
           // Already tested node as type element and of name "ApplicationSettings".
           // Read attributes of element "ApplicationSettings".
               const XMLCh* xmlch_OptionA
                 = currentElement->getAttribute(ATTR_OptionA);
               m_OptionA = XMLString::transcode(xmlch_OptionA);

               const XMLCh* xmlch_OptionB
                 = currentElement->getAttribute(ATTR_OptionB);
               m_OptionB = XMLString::transcode(xmlch_OptionB);

               break;  // Data found. No need to look at other elements in tree.
            }
         }
      }
   }
}
void GetConfig::readConfigFile(字符串和配置文件)
抛出(标准::运行时错误)
{
//配置DOM解析器。
m_ConfigFileParser->setValidationScheme(XercesDOMParser::Val_Never);
m_ConfigFileParser->setdonamespace(false);
m_ConfigFileParser->setDoSchema(false);
m_ConfigFileParser->setLoadExternalDTD(false);
尝试
{
m_ConfigFileParser->parse(configFile.c_str());
//无需释放父解析器对象拥有的指针
DOMDocument*xmlDoc=m_ConfigFileParser->getDocument();
//获取顶级元素:名称为“root”。没有“root”属性
doElement*elementRoot=xmlDoc->getDocumentElement();
如果(!elementRoot)抛出(std::runtime_错误(“空XML文档”);
//解析感兴趣的标记的XML文件:“应用程序设置”
//查看嵌套在“根”中的一个级别。(根的子级)
DOMNodeList*children=elementRoot->getChildNodes();
const XMLSize_t nodeCount=children->getLength();
//对于所有节点,XML树中“root”的子节点。
对于(XMLSize_t xx=0;xxitem(xx);
如果(currentNode->getNodeType()&&//true)不为NULL
currentNode->getNodeType()==DOMNode::ELEMENT\u NODE)//是元素
{
//找到作为元素的节点。将节点重新转换为元素
DOMELENT*currentElement
=dynamic_cast(currentNode);
if(XMLString::equals(currentElement->getTagName(),TAG_ApplicationSettings))
{
//已将节点测试为类型元素,名称为“ApplicationSettings”。
//读取元素“ApplicationSettings”的属性。
常数XMLCh*XMLCh_OptionA
=currentElement->getAttribute(属性选项A);
m_OptionA=XMLString::transcode(xmlch_OptionA);
常量XMLCh*XMLCh_选项b
=currentElement->getAttribute(属性选项B);
m_OptionB=XMLString::transcode(xmlch_OptionB);
break;//找到数据。无需查看树中的其他元素。
}
}
}
}
}
那么,有人能帮我在这个函数中实现lockf吗