LCOV - code coverage report
Current view: top level - source/ps/XML - Xeromyces.h (source / functions) Hit Total Coverage
Test: 0 A.D. test coverage report Lines: 1 1 100.0 %
Date: 2026-12-03 01:19:39 Functions: 0 0 -

          Line data    Source code
       1             : /* Copyright (C) 2026 Wildfire Games.
       2             :  * This file is part of 0 A.D.
       3             :  *
       4             :  * 0 A.D. is free software: you can redistribute it and/or modify
       5             :  * it under the terms of the GNU General Public License as published by
       6             :  * the Free Software Foundation, either version 2 of the License, or
       7             :  * (at your option) any later version.
       8             :  *
       9             :  * 0 A.D. is distributed in the hope that it will be useful,
      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      12             :  * GNU General Public License for more details.
      13             :  *
      14             :  * You should have received a copy of the GNU General Public License
      15             :  * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
      16             :  */
      17             : 
      18             : /*
      19             :   Xeromyces file-loading interface.
      20             :   Automatically creates and caches relatively
      21             :   efficient binary representations of XML files.
      22             : */
      23             : 
      24             : #ifndef INCLUDED_XEROMYCES
      25             : #define INCLUDED_XEROMYCES
      26             : 
      27             : #include "ps/Errors.h"
      28             : #include "ps/Singleton.h"
      29             : #include "ps/XMB/XMBData.h"
      30             : #include "ps/XMB/XMBStorage.h"
      31             : 
      32             : #include <string>
      33             : 
      34             : class RelaxNGValidator;
      35             : 
      36             : ERROR_GROUP(Xeromyces);
      37             : ERROR_TYPE(Xeromyces, XMLOpenFailed);
      38             : ERROR_TYPE(Xeromyces, XMLParseError);
      39             : ERROR_TYPE(Xeromyces, XMLValidationFailed);
      40             : 
      41       44334 : class CXeromyces : public XMBData
      42             : {
      43             :     friend class TestXMBData;
      44             :     friend class XMBData;
      45             : public:
      46             :     /**
      47             :      * Load from an XML file (with invisible XMB caching).
      48             :      */
      49             :     PSRETURN Load(const PIVFS& vfs, const VfsPath& filename, const std::string& validatorName = "");
      50             : 
      51             :     /**
      52             :      * Load from an in-memory XML string (with no caching).
      53             :      */
      54             :     PSRETURN LoadString(const char* xml, const std::string& validatorName = "");
      55             : 
      56             :     /**
      57             :      * Convert the given XML file into an XMB in the archive cache.
      58             :      * Returns the XMB path in @p archiveCachePath.
      59             :      * Returns false on error.
      60             :      */
      61             :     bool GenerateCachedXMB(const PIVFS& vfs, const VfsPath& sourcePath, VfsPath& archiveCachePath, const std::string& validatorName = "");
      62             : 
      63             : private:
      64             :     PSRETURN ConvertFile(const PIVFS& vfs, const VfsPath& filename, const VfsPath& xmbPath, const std::string& validatorName);
      65             : 
      66             :     XMBStorage m_Data;
      67             : };
      68             : 
      69             : class CXeromycesEngine : public Singleton<CXeromycesEngine>
      70             : {
      71             :     friend CXeromyces;
      72             : public:
      73             :     /**
      74             :      * This should be run in the main thread, before any thread uses libxml2.
      75             :      */
      76             :     CXeromycesEngine();
      77             :     ~CXeromycesEngine();
      78             : 
      79             :     bool AddValidator(const PIVFS& vfs, const std::string& name, const VfsPath& grammarPath);
      80             :     bool ValidateEncoded(const std::string& name, const std::string& filename, const std::string& document);
      81             : 
      82             : private:
      83             :     RelaxNGValidator& GetValidator(const std::string& name);
      84             : };
      85             : 
      86             : #define g_Xeromyces CXeromycesEngine::GetSingleton()
      87             : 
      88             : #define _XERO_MAKE_UID2__(p,l) p ## l
      89             : #define _XERO_MAKE_UID1__(p,l) _XERO_MAKE_UID2__(p,l)
      90             : 
      91             : #define _XERO_CHILDREN _XERO_MAKE_UID1__(_children_, __LINE__)
      92             : #define _XERO_I _XERO_MAKE_UID1__(_i_, __LINE__)
      93             : 
      94             : #endif // INCLUDED_XEROMYCES

Generated by: LCOV version 1.16