Skip to content

Commit

Permalink
Add XML vocabulary
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanoBilenchi committed Nov 20, 2024
1 parent d6a3daa commit 540e04a
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 1 deletion.
4 changes: 4 additions & 0 deletions include/cowl_vocab.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "cowl_owl_vocab.h"
#include "cowl_rdf_vocab.h"
#include "cowl_rdfs_vocab.h"
#include "cowl_xml_vocab.h"
#include "cowl_xsd_vocab.h"
// IWYU pragma: end_exports

Expand All @@ -37,6 +38,9 @@ typedef struct CowlVocab {
/// RDFS vocabulary.
CowlRDFSVocab const *rdfs;

/// XML vocabulary.
CowlXMLVocab const *xml;

/// XSD vocabulary.
CowlXSDVocab const *xsd;

Expand Down
53 changes: 53 additions & 0 deletions include/cowl_xml_vocab.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* Defines CowlXMLVocab.
*
* @author Ivano Bilenchi
*
* @copyright Copyright (c) 2024 SisInf Lab, Polytechnic University of Bari
* @copyright <http://swot.sisinflab.poliba.it>
* @copyright SPDX-License-Identifier: EPL-2.0
*
* @file
*/

#ifndef COWL_XML_VOCAB_H
#define COWL_XML_VOCAB_H

#include "cowl_attrs.h"
#include "cowl_macros.h"

COWL_BEGIN_DECLS

/// @cond
cowl_struct_decl(CowlString);
/// @endcond

/// The XML vocabulary.
typedef struct CowlXMLVocab {

/// XML namespace.
CowlString *ns;

/// XML prefix.
CowlString *prefix;

/// xmlns namespace.
CowlString *xmlns_ns;

/// xmlns prefix.
CowlString *xmlns_prefix;

} CowlXMLVocab;

/**
* Returns the XML vocabulary.
*
* @return The XML vocabulary.
*/
COWL_API
COWL_CONST
CowlXMLVocab const *cowl_xml_vocab(void);

COWL_END_DECLS

#endif // COWL_XML_VOCAB_H
6 changes: 5 additions & 1 deletion src/cowl_vocab.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include "cowl_rdfs_vocab_private.h"
#include "cowl_ret.h"
#include "cowl_string_private.h"
#include "cowl_xml_vocab.h"
#include "cowl_xml_vocab_private.h"
#include "cowl_xsd_vocab.h"
#include "cowl_xsd_vocab_private.h"
#include "ulib.h"
Expand All @@ -29,11 +31,12 @@ CowlVocab const *cowl_vocab(void) {

cowl_ret cowl_vocab_init(void) {
if (cowl_owl_vocab_init() || cowl_rdf_vocab_init() || cowl_rdfs_vocab_init() ||
cowl_xsd_vocab_init())
cowl_xml_vocab_init() || cowl_xsd_vocab_init())
return COWL_ERR_MEM;
vocab.owl = cowl_owl_vocab();
vocab.rdf = cowl_rdf_vocab();
vocab.rdfs = cowl_rdfs_vocab();
vocab.xml = cowl_xml_vocab();
vocab.xsd = cowl_xsd_vocab();
return COWL_OK;
}
Expand All @@ -42,6 +45,7 @@ void cowl_vocab_deinit(void) {
cowl_owl_vocab_deinit();
cowl_rdf_vocab_deinit();
cowl_rdfs_vocab_deinit();
cowl_xml_vocab_deinit();
cowl_xsd_vocab_deinit();
}

Expand Down
43 changes: 43 additions & 0 deletions src/cowl_xml_vocab.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* @author Ivano Bilenchi
*
* @copyright Copyright (c) 2024 SisInf Lab, Polytechnic University of Bari
* @copyright <http://swot.sisinflab.poliba.it>
* @copyright SPDX-License-Identifier: EPL-2.0
*
* @file
*/

#include "cowl_xml_vocab.h"
#include "cowl_ret.h"
#include "cowl_vocab_private.h"
#include "cowl_xml_vocab_private.h"

static CowlXMLVocab vocab;

static inline cowl_ret cowl_xml_vocab_validate(void) {
if (vocab.ns && vocab.prefix && vocab.xmlns_ns && vocab.xmlns_prefix) return COWL_OK;
return COWL_ERR_MEM;
}

cowl_ret cowl_xml_vocab_init(void) {
vocab = (struct CowlXMLVocab){
.ns = cowl_string_vocab_intern("http://www.w3.org/XML/1998/namespace"),
.prefix = cowl_string_vocab("xml"),
.xmlns_ns = cowl_string_vocab_intern("http://www.w3.org/2000/xmlns/"),
.xmlns_prefix = cowl_string_vocab("xmlns"),
};

return cowl_xml_vocab_validate();
}

void cowl_xml_vocab_deinit(void) {
cowl_string_vocab_free(vocab.ns);
cowl_string_vocab_free(vocab.prefix);
cowl_string_vocab_free(vocab.xmlns_ns);
cowl_string_vocab_free(vocab.xmlns_prefix);
}

CowlXMLVocab const *cowl_xml_vocab(void) {
return &vocab;
}
25 changes: 25 additions & 0 deletions src/cowl_xml_vocab_private.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* @author Ivano Bilenchi
*
* @copyright Copyright (c) 2024 SisInf Lab, Polytechnic University of Bari
* @copyright <http://swot.sisinflab.poliba.it>
* @copyright SPDX-License-Identifier: EPL-2.0
*
* @file
*/

#ifndef COWL_XML_VOCAB_PRIVATE_H
#define COWL_XML_VOCAB_PRIVATE_H

#include "cowl_attrs.h"
#include "cowl_ret.h"
#include "cowl_xml_vocab.h" // IWYU pragma: export

COWL_BEGIN_DECLS

cowl_ret cowl_xml_vocab_init(void);
void cowl_xml_vocab_deinit(void);

COWL_END_DECLS

#endif // COWL_XML_VOCAB_PRIVATE_H

0 comments on commit 540e04a

Please sign in to comment.