text: /*
   * Copyright 2022 The Naja Authors.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *      https://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  #include "PySNLLibrary.h"
  
  #include "PySNLDB.h"
  
  #include "SNLLibrary.h"
  
  namespace PYSNL {
  
  using namespace naja::SNL;
  
  static PyObject* PySNLLibrary_create(PyObject*, PyObject* args) {
    PyObject* arg0 = nullptr;
    const char* arg1 = nullptr;
    if (not PyArg_ParseTuple(args, "O|s:SNLLibrary.create", &arg0, &arg1)) {
      setError("malformed SNLDB create");
      return nullptr;
    }
    SNLName name;
    if (arg1) {
      name = SNLName(arg1);
    }
  
    SNLLibrary* lib = nullptr;
    SNLTRY
    if (IsPySNLDB(arg0)) {
      lib = SNLLibrary::create(PYSNLDB_O(arg0), name);
    } else if (IsPySNLLibrary(arg0)) {
      lib = SNLLibrary::create(PYSNLLibrary_O(arg0), name);
    } else {
      setError("SNLLibrary creator accepts as first argument either a SNLDB or a SNLLibrary");
      return nullptr;
    }
    SNLCATCH
    return PySNLLibrary_Link(lib);
  }
  
  PyMethodDef PySNLLibrary_Methods[] = {
    { "create", (PyCFunction)PySNLLibrary_create, METH_VARARGS|METH_STATIC,
      "SNLLibrary creator"},
    {NULL, NULL, 0, NULL}           /* sentinel */
  };
  
  DBoDestroyAttribute(PySNLLibrary_destroy, PySNLLibrary)
  DBoDeallocMethod(SNLLibrary)
  
  DBoLinkCreateMethod(SNLLibrary)
  PyTypeObjectLinkPyType(SNLLibrary)
  PyTypeObjectDefinitions(SNLLibrary)
  
  }
  