"Fossies" - the Fresh Open Source Software Archive

Member "fimex-1.4.1/modules/python/pyfimex0_NcmlCDMReader.cc" (30 Oct 2019, 2556 Bytes) of package /linux/privat/fimex-1.4.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "pyfimex0_NcmlCDMReader.cc" see the Fossies "Dox" file reference documentation.

    1 /*
    2  * Fimex, pyfimex0_NcmlCDMReader.cc
    3  *
    4  * (C) Copyright 2019, met.no
    5  *
    6  * Project Info:  https://wiki.met.no/fimex/start
    7  *
    8  * This library is free software; you can redistribute it and/or modify it
    9  * under the terms of the GNU Lesser General Public License as published by
   10  * the Free Software Foundation; either version 2.1 of the License, or
   11  * (at your option) any later version.
   12  *
   13  * This library is distributed in the hope that it will be useful, but
   14  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
   15  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
   16  * License for more details.
   17  *
   18  * You should have received a copy of the GNU Lesser General Public
   19  * License along with this library; if not, write to the Free Software
   20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
   21  * USA.
   22  */
   23 
   24 #include "fimex/NcmlCDMReader.h"
   25 #include "fimex/StringUtils.h"
   26 #include "fimex/XMLDoc.h"
   27 #include "fimex/XMLInputDoc.h"
   28 #include "fimex/XMLInputFile.h"
   29 #include "fimex/XMLInputString.h"
   30 
   31 #include "pyfimex0_helpers.h"
   32 
   33 namespace MetNoFimex {
   34 typedef std::shared_ptr<NcmlCDMReader> NcmlCDMReader_p;
   35 } // namespace MetNoFimex
   36 
   37 using namespace MetNoFimex;
   38 namespace py = pybind11;
   39 
   40 namespace {
   41 
   42 // FIXME this is copied from CDMFileReaderFactory.cc
   43 
   44 XMLInputDoc createXMLInput(const XMLInput& xi)
   45 {
   46     return XMLInputDoc(xi.id(), xi.getXMLDoc());
   47 }
   48 
   49 XMLInputDoc createXMLInput(const std::string& configXML)
   50 {
   51     if (configXML.empty()) {
   52         return XMLInputDoc("", XMLDoc_p());
   53     } else if (starts_with(configXML, "<?xml ")) {
   54         return createXMLInput(XMLInputString(configXML));
   55     } else {
   56         return createXMLInput(XMLInputFile(configXML));
   57     }
   58 }
   59 
   60 NcmlCDMReader_p createNcmlReader1(const std::string& configXML)
   61 {
   62     XMLInputDoc configDoc = createXMLInput(configXML);
   63     return std::make_shared<NcmlCDMReader>(configDoc);
   64 }
   65 
   66 NcmlCDMReader_p createNcmlReader2(CDMReader_p reader, const std::string& configXML)
   67 {
   68     XMLInputDoc configDoc = createXMLInput(configXML);
   69     return std::make_shared<NcmlCDMReader>(reader, configDoc);
   70 }
   71 
   72 } // namespace
   73 
   74 void pyfimex0_NcmlCDMReader(py::module m)
   75 {
   76     py::class_<NcmlCDMReader, NcmlCDMReader_p, CDMReader>(m, "_NcmlCDMReader");
   77 
   78     m.def("createNcmlReader", createNcmlReader1,
   79           "Create a NcML reader using sources specified in the ncml file or inline xml.");
   80     m.def("createNcmlReader", createNcmlReader2,
   81           "Create a NcML reader using the specified source and the ncml file or inline xml.");
   82 }