initial commit

This commit is contained in:
Alexey Fedoseev
2024-04-11 00:03:38 +03:00
commit aa6509b8f9
6 changed files with 2229 additions and 0 deletions

165
LICENSE Normal file
View File

@@ -0,0 +1,165 @@
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.
0. Additional Definitions.
As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.
"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.
An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.
A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
Version".
The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.
The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
version:
a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:
a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license
document.
4. Combined Works.
You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:
a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license
document.
c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.
d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.
1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
Version.
e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)
5. Combined Libraries.
You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:
a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.

48
Makefile Normal file
View File

@@ -0,0 +1,48 @@
LIB_TARGET_STATIC := libcyberiadamlpp.a
LIB_TARGET_DYNAMIC := libcyberiadamlpp.so
ifeq ($(DYNAMIC), 1)
LIB_TARGET := $(LIB_TARGET_DYNAMIC)
else
LIB_TARGET := $(LIB_TARGET_STATIC)
endif
TEST_TARGET := cyberiadapp_test
LIB_SOURCES := cyberiadamlpp.cpp
TEST_SOURCES := test.cpp
LIB_OBJECTS := $(patsubst %.cpp, %.o, $(LIB_SOURCES))
TEST_OBJECTS := $(patsubst %.cpp, %.o, $(TEST_SOURCES))
ifeq ($(DEBUG), 1)
CFLAGS := -Wall -Wshadow -Wconversion -fPIC -g3 -D__DEBUG__
LFLAGS :=
else
CFLAGS := -fPIC
LFLAGS :=
endif
INCLUDE := -I. -I/usr/include/libxml2 -I./cyberiadaml
LIBS := -L/usr/lib -lxml2 -L./cyberiadaml -lcyberiadaml
TEST_LIBS := -L. -lcyberiadamlpp
$(LIB_TARGET): $(LIB_OBJECTS)
ifeq ($(DYNAMIC), 1)
g++ -shared $(LIBS) $(LIB_OBJECTS) -o $@
else
ar rcs $@ $(LIB_OBJECTS)
endif
$(TEST_TARGET): $(TEST_OBJECTS) $(LIB_TARGET) $(LIB_ORJECTS)
g++ $(TEST_OBJECTS) -Wl,-\( $(LIBS) $(TEST_LIBS) -Wl,-\) -o $@
%.o: %.cpp
g++ -c $< $(CFLAGS) $(INCLUDE) -o $@
clean:
rm -f *~ *.o $(TARGET) $(TEST_TARGET) $(LIB_TARGET_STATIC) $(LIB_TARGET_DYNAMIC)
test: $(TEST_TARGET)
all: $(LIB_TARGET) $(TEST_TARGET)
.PHONY: all clean test

24
README.md Normal file
View File

@@ -0,0 +1,24 @@
# The Cyberida State Machine C++ Library
The C++ library for processing CyberiadaML - the version of GraphML for storing state machine graphs
used by the Cyberiada Project, the Berloga Project games and the Orbita Simulator.
This is C++ wrapper interface to the libcyberiadaml C library.
The code is distributed under the Lesser GNU Public License (version 3), the documentation -- under
the GNU Free Documentation License (version 1.3).
## Requirements
* libcyberidaml
* libstdc++
## Installation
Run `make` to build the library binaries.
Run `make test` to build the test program.
Use variables:
* `DEBUG=1` debug version of the library
* `DYNAMIC=1` build shared version of the library

1344
cyberiadamlpp.cpp Normal file

File diff suppressed because it is too large Load Diff

596
cyberiadamlpp.h Normal file
View File

@@ -0,0 +1,596 @@
/* -----------------------------------------------------------------------------
* The Cyberiada GraphML library implemention
*
* The C++ library header
*
* Copyright (C) 2024 Alexey Fedoseev <aleksey@fedoseev.net>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see https://www.gnu.org/licenses/
*
* ----------------------------------------------------------------------------- */
#ifndef __CYBERIADA_ML_CPP_H
#define __CYBERIADA_ML_CPP_H
#include <string>
#include <list>
#include <vector>
#include <ostream>
#include <cyberiadaml.h>
// -----------------------------------------------------------------------------
// The Cyberiada GraphML classes
// -----------------------------------------------------------------------------
namespace Cyberiada {
// -----------------------------------------------------------------------------
// Base types
// -----------------------------------------------------------------------------
// Cyberiada diagram element types:
enum ElementType {
elementRoot, // document (root namespace)
elementSM, // state machine
elementSimpleState, // simple state
elementCompositeState, // composite state
elementComment, // informal (human-readable) comment node
elementFormalComment, // formal (machine-readable) comment node
elementInitial, // initial pseudostate
elementFinal, // final state
elementChoice, // choice pseudostate
elementTransition // transition
};
typedef std::string String;
typedef String ID;
typedef String Name;
typedef String QualifiedName;
typedef String Color;
const String QUALIFIED_NAME_SEPARATOR = "::";
// -----------------------------------------------------------------------------
// Base Element
// -----------------------------------------------------------------------------
class Element {
public:
Element(Element* parent, ElementType type, const ID& id);
Element(Element* parent, ElementType type, const ID& id, const Name& name);
virtual ~Element() {}
ElementType get_type() const { return type; }
const ID& get_id() const { return id; }
bool has_name() const { return name_is_set; }
const Name& get_name() const { return name; }
void set_name(const Name& name);
bool has_qualified_name() const;
QualifiedName qualified_name() const;
bool is_root() const { return !parent; }
Element* get_parent() { return parent; }
virtual bool has_children() const { return false; }
virtual size_t elements_count() const { return 1; }
virtual bool has_geometry() const = 0;
friend std::ostream& operator<<(std::ostream& os, const Element& e);
protected:
Element* find_root();
void set_type(ElementType t) { type = t; };
virtual std::ostream& dump(std::ostream& os) const;
private:
ElementType type;
ID id;
Name name;
bool name_is_set;
Element* parent;
};
std::ostream& operator<<(std::ostream& os, const Element& e);
// -----------------------------------------------------------------------------
// Geometry
// -----------------------------------------------------------------------------
struct Point {
Point(): valid(false) {}
Point(float _x, float _y):
valid(true), x(_x), y(_y) {}
Point(CyberiadaPoint* p);
bool valid;
float x, y;
};
struct Rect {
Rect(): valid(false) {}
Rect(float _x, float _y, float _width, float _height):
valid(true), x(_x), y(_y), width(_width), height(_height) {}
Rect(CyberiadaRect* r);
bool valid;
float x, y;
float width, height;
};
typedef std::list<Point> Polyline;
std::ostream& operator<<(std::ostream& os, const Point& p);
std::ostream& operator<<(std::ostream& os, const Rect& r);
std::ostream& operator<<(std::ostream& os, const Polyline& pl);
// -----------------------------------------------------------------------------
// Comment
// -----------------------------------------------------------------------------
enum CommentSubjectType {
commentSubjectElement = 0,
commentSubjectName,
commentSubjectData
};
class CommentSubject {
public:
CommentSubject(Element* element,
const Point& source = Point(), const Point& target = Point(), const Polyline& pl = Polyline());
CommentSubject(Element* element, CommentSubjectType type, const String& fragment,
const Point& source = Point(), const Point& target = Point(), const Polyline& pl = Polyline());
CommentSubject& operator=(const CommentSubject& cs);
CommentSubjectType get_type() const { return type; }
const Element* get_element() const { return element; }
Element* get_element() { return element; }
bool has_fragment() const { return has_frag; }
const String& get_fragment() const { return fragment; }
bool has_geometry() const { return source_point.valid || target_point.valid || !polyline.empty(); }
const Point& get_geometry_source_point() const { return source_point; }
const Point& get_geometry_target_point() const { return target_point; }
const Polyline& get_geometry_polyline() const { return polyline; }
protected:
std::ostream& dump(std::ostream& os) const;
friend std::ostream& operator<<(std::ostream& os, const CommentSubject& cs);
private:
CommentSubjectType type;
Element* element;
bool has_frag;
String fragment;
Point source_point;
Point target_point;
Polyline polyline;
};
std::ostream& operator<<(std::ostream& os, const CommentSubject& cs);
class Comment: public Element {
public:
Comment(Element* parent, const ID& id, const String& body, bool human_readable = true,
const String& markup = String(), const Rect& rect = Rect(), const Color& color = Color());
Comment(Element* parent, const ID& id, const String& body, bool human_readable, const Name& name,
const String& markup = String(), const Rect& rect = Rect(), const Color& color = Color());
bool is_human_readable() const { return human_readable; }
bool is_machine_readable() const { return !human_readable; }
bool has_subjects() const { return !subjects.empty(); }
const std::list<CommentSubject>& get_subjects() const { return subjects; }
void add_subject(const CommentSubject& s);
void remove_subject(CommentSubjectType type, const String& fragment);
virtual bool has_geometry() const { return geometry_rect.valid; }
const Rect& get_geometry_rect() const { return geometry_rect; }
virtual bool has_children() const { return false; }
bool has_color() const { return !color.empty(); }
const Color& get_color() const { return color; }
bool has_markup() const { return !markup.empty(); }
const String& get_markup() const { return markup; }
protected:
virtual std::ostream& dump(std::ostream& os) const;
private:
void update_comment_type();
String body;
String markup;
bool human_readable;
Rect geometry_rect;
std::list<CommentSubject> subjects;
Color color;
};
// -----------------------------------------------------------------------------
// Vertex
// -----------------------------------------------------------------------------
class Vertex: public Element {
public:
Vertex(Element* parent, ElementType type, const ID& id, const Point& pos = Point());
Vertex(Element* parent, ElementType type, const ID& id, const Name& name, const Point& pos = Point());
virtual bool has_geometry() const { return geometry_point.valid; }
const Point& get_geometry_point() const { return geometry_point; }
virtual bool has_children() const { return false; }
protected:
virtual std::ostream& dump(std::ostream& os) const;
private:
Point geometry_point;
};
// -----------------------------------------------------------------------------
// Collection of Elements
// (the combination of Namespace and Region from the PRIMS standard)
// -----------------------------------------------------------------------------
typedef std::list<const Element*> ConstElementList;
typedef std::list<Element*> ElementList;
typedef std::vector<ElementType> ElementTypes;
class ElementCollection: public Element {
public:
ElementCollection(Element* parent, ElementType type, const ID& id,
const Name& name, const Rect& rect = Rect(), const Color& color = Color());
virtual ~ElementCollection();
bool has_qualified_name(const ID& element_id) const;
QualifiedName qualified_name(const ID& element_id) const;
virtual bool has_children() const { return !children.empty(); }
virtual size_t children_count() const { return children.size(); }
virtual size_t elements_count() const;
const Element* find_element_by_id(const ID& id) const;
Element* find_element_by_id(const ID& id);
ConstElementList find_elements_by_type(ElementType type) const;
ConstElementList find_elements_by_types(const ElementTypes& types) const;
ElementList find_elements_by_type(ElementType type);
ElementList find_elements_by_types(const ElementTypes& types);
virtual void add_element(Element* e);
virtual void remove_element(const ID& id);
void clear();
std::list<const Vertex*> get_vertexes() const;
std::list<Vertex*> get_vertexes();
virtual bool has_geometry() const { return geometry_rect.valid; }
const Rect& get_geometry_rect() const { return geometry_rect; }
bool has_color() const { return !color.empty(); }
const Color& get_color() const { return color; }
protected:
virtual std::ostream& dump(std::ostream& os) const;
ElementList children;
private:
Rect geometry_rect;
Color color;
};
// -----------------------------------------------------------------------------
// Pseudostate
// -----------------------------------------------------------------------------
class Pseudostate: public Vertex {
public:
Pseudostate(Element* parent, ElementType type, const ID& id, const Point& p = Point());
Pseudostate(Element* parent, ElementType type, const ID& id, const Name& name, const Point& p = Point());
};
// -----------------------------------------------------------------------------
// Initial pseudostate
// -----------------------------------------------------------------------------
class InitialPseudostate: public Pseudostate {
public:
InitialPseudostate(Element* parent, const ID& id, const Point& p = Point());
InitialPseudostate(Element* parent, const ID& id, const Name& name, const Point& p = Point());
protected:
virtual std::ostream& dump(std::ostream& os) const;
};
// -----------------------------------------------------------------------------
// Choice pseudostate
// -----------------------------------------------------------------------------
class ChoicePseudostate: public Pseudostate {
public:
ChoicePseudostate(Element* parent, const ID& id,
const Rect& r = Rect(), const Color& color = Color());
ChoicePseudostate(Element* parent, const ID& id, const Name& name,
const Rect& r = Rect(), const Color& color = Color());
virtual bool has_geometry() const { return geometry_rect.valid; }
const Rect& get_geometry_rect() const { return geometry_rect; }
bool has_color() const { return !color.empty(); }
const Color& get_color() const { return color; }
protected:
virtual std::ostream& dump(std::ostream& os) const;
Rect geometry_rect;
Color color;
};
// -----------------------------------------------------------------------------
// Final state
// -----------------------------------------------------------------------------
class FinalState: public Vertex {
public:
FinalState(Element* parent, const ID& id, const Point& point = Point());
FinalState(Element* parent, const ID& id, const Name& name, const Point& point = Point());
protected:
virtual std::ostream& dump(std::ostream& os) const;
};
// -----------------------------------------------------------------------------
// Action
// -----------------------------------------------------------------------------
// Cyberiada action types:
typedef enum {
actionTransition,
actionEntry,
actionExit
} ActionType;
typedef String Event;
typedef String Guard;
typedef String Behavior;
class Action {
public:
Action(ActionType type, const Guard& guard = Guard(), const Behavior& behavior = Behavior());
Action(const Event& trigger = Event(), const Guard& guard = Guard(), const Behavior& behavior = Behavior());
ActionType get_type() const { return type; }
bool has_trigger() const { return !trigger.empty(); }
const Event& get_trigger() { return trigger; }
bool has_guard() const { return !guard.empty(); }
const Guard& get_guard() { return guard; }
bool has_behavior() const { return !behavior.empty(); }
const Behavior& get_behavior() { return behavior; }
protected:
std::ostream& dump(std::ostream& os) const;
friend std::ostream& operator<<(std::ostream& os, const Action& a);
private:
ActionType type;
Event trigger;
Guard guard;
Behavior behavior;
};
std::ostream& operator<<(std::ostream& os, const Action& a);
// -----------------------------------------------------------------------------
// State
// -----------------------------------------------------------------------------
class State: public ElementCollection {
public:
State(Element* parent, const ID& id, const Name& name,
const Rect& r = Rect(), const Color& color = Color());
virtual void add_element(Element* e);
virtual void remove_element(const ID& id);
bool is_simple_state() const { return get_type() == elementSimpleState; }
bool is_composite_state() const { return get_type() == elementCompositeState; }
std::list<const State*> get_substates() const;
std::list<State*> get_substates();
bool has_actions() const { return !actions.empty(); }
const std::list<Action>& get_actions() const { return actions; }
std::list<Action>& get_actions() { return actions; }
void add_action(const Action& a);
protected:
virtual std::ostream& dump(std::ostream& os) const;
void update_state_type();
std::list<Action> actions;
};
// -----------------------------------------------------------------------------
// Transition
// -----------------------------------------------------------------------------
class Transition: public Element {
public:
Transition(Element* parent, const ID& id, Element* source, Element* target, const Action& action,
const Polyline& pl = Polyline(), const Point& sp = Point(), const Point& tp = Point(),
const Point& label = Point(), const Color& color = Color());
const Element* source_element() const { return source; }
const Element* target_element() const { return target; }
bool has_action() const { return (action.has_trigger() ||
action.has_guard() ||
action.has_behavior()); }
const Action& get_action() const { return action; }
Action& get_action() { return action; }
bool has_geometry() const { return (source_point.valid ||
target_point.valid ||
label_point.valid ||
has_polyline()); }
bool has_polyline() const { return !polyline.empty(); }
const Polyline& get_geometry_polyline() const { return polyline; }
const Point& get_source_point() const { return source_point; }
const Point& get_target_point() const { return target_point; }
const Point& get_label_point() const { return label_point; }
bool has_color() const { return !color.empty(); }
protected:
virtual std::ostream& dump(std::ostream& os) const;
private:
Element* source;
Element* target;
Action action;
Point source_point;
Point target_point;
Point label_point;
Polyline polyline;
Color color;
};
// -----------------------------------------------------------------------------
// State Machine
// -----------------------------------------------------------------------------
class StateMachine: public ElementCollection {
public:
StateMachine(Element* parent, const ID& id, const Name& name = "", const Rect& r = Rect());
std::list<const Comment*> get_comments() const;
std::list<Comment*> get_comments();
std::list<const Transition*> get_transitions() const;
std::list<Transition*> get_transitions();
protected:
virtual std::ostream& dump(std::ostream& os) const;
};
// -----------------------------------------------------------------------------
// Cyberiada-GraphML document
// -----------------------------------------------------------------------------
struct DocumentMetainformation {
String standard_version; // PRIMS standard version
String platform_name; // target platform name
String platform_version; // target platform version
String platform_language; // target platform language
String target_system; // target system controlled by the SM
String name; // document name
String author; // document author
String contact; // document author's contact
String description; // document description
String version; // document version
String date; // document date
bool transition_order_flag;
bool event_propagation_flag;
};
class Document: public ElementCollection {
public:
Document();
void reset();
StateMachine* new_state_machine(const String& sm_nam, const Rect& r = Rect());
StateMachine* new_state_machine(const ID& id, const String& sm_name, const Rect& r = Rect());
void load(const String& path);
void save(const String& path) const;
const DocumentMetainformation& meta() const { return metainfo; }
DocumentMetainformation& meta() { return metainfo; }
std::list<const StateMachine*> get_state_machines() const;
std::list<StateMachine*> get_state_machines();
protected:
virtual std::ostream& dump(std::ostream& os) const;
private:
void check_cyberiada_error(int res, const String& msg = "");
ID generate_sm_id() const;
ID generate_vertex_id(const Element* element) const;
ID generate_transition_id(const String& source_id, const String& target_id) const;
void import_nodes_recursively(ElementCollection* collection, CyberiadaNode* nodes);
void import_edges(ElementCollection* collection, CyberiadaEdge* edges);
String format;
DocumentMetainformation metainfo;
};
// -----------------------------------------------------------------------------
// Exceptions
// -----------------------------------------------------------------------------
class Exception {
public:
Exception(const String& msg = "", const String& e = "Generic Error"):
error_type(e), message(msg) {}
String str() const { return error_type + ": " + message; }
private:
String error_type;
String message;
};
// -----------------------------------------------------------------------------
class FormatException: public Exception {
public:
FormatException(const String& msg = "", const String& e = "Format Exception"):
Exception(e, msg) {}
};
// -----------------------------------------------------------------------------
class XMLException: public FormatException {
public:
XMLException(const String& msg = "", const String& e = "XML Exception"):
FormatException(msg, e) {}
};
// -----------------------------------------------------------------------------
class CybMLException: public FormatException {
public:
CybMLException(const String& msg = "", const String& e = "CyberiadaML Exception"):
FormatException(msg, e) {}
};
// -----------------------------------------------------------------------------
class ActionException: public CybMLException {
public:
ActionException(const String& msg = "", const String& e = "Action Exception"):
CybMLException(msg, e) {}
};
// -----------------------------------------------------------------------------
class MetainformationException: public FormatException {
public:
MetainformationException(const String& msg = "", const String& e = "Metainfo Exception"):
FormatException(msg, e) {}
};
// -----------------------------------------------------------------------------
class ParametersException: public Exception {
public:
ParametersException(const String& msg = "", const String& e = "Parameters Exception"):
Exception(msg, e) {}
};
// -----------------------------------------------------------------------------
class NotFoundException: public ParametersException {
public:
NotFoundException(const String& msg = "", const String& e = "Not Found Exception"):
ParametersException(msg, e) {}
};
// -----------------------------------------------------------------------------
class AssertException: public Exception {
public:
AssertException(const String& msg, const String& e = "Assert Exception"):
Exception(msg, e) {}
};
// -----------------------------------------------------------------------------
};
#endif

52
test.cpp Normal file
View File

@@ -0,0 +1,52 @@
/* -----------------------------------------------------------------------------
* The Cyberiada GraphML C++ library implemention
*
* The testing program
*
* Copyright (C) 2024 Alexey Fedoseev <aleksey@fedoseev.net>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see https://www.gnu.org/licenses/
* ----------------------------------------------------------------------------- */
#include <iostream>
#include <stdlib.h>
#include "cyberiadamlpp.h"
using namespace Cyberiada;
using namespace std;
void usage(const char* program)
{
cerr << program << " <path-to-graphml-file>" << endl;
cerr << "\tPrint the graphml SM structure of the file <path-to-graphml-file>" << endl;
exit(1);
}
int main(int argc, char** argv)
{
Document d;
if (argc != 2) {
usage(argv[0]);
}
try {
d.load(argv[1]);
cout << d << endl;
} catch (const Cyberiada::Exception& e) {
cerr << "Error while opening graphml file: " << e.str() << endl;
return 2;
}
return 0;
}