~holger-seelig/titania/3.0

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
// /* -*- Mode: C++; tab-width: 3; indent-tabs-mode: tab; c-basic-offset: 3 -*- */
// /*************************************************************************
//  *
//  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
//  *
//  * Copyright 1999, 2012 Holger Seelig <holger.seelig@yahoo.de>.
//  *
//  * Titania - a multi-platform office productivity suite
//  *
//  * This file is part of the Titania Project.
//  *
//  * Titania is free software: you can redistribute it and/or modify
//  * it under the terms of the GNU Lesser General Public License version 3
//  * only, as published by the Free Software Foundation.
//  *
//  * Titania 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 version 3 for more details
//  * (a copy is included in the LICENSE file that accompanied this code).
//  *
//  * You should have received a copy of the GNU Lesser General Public License
//  * version 3 along with Titania.  If not, see
//  * <http://www.gnu.org/licenses/lgpl.html>
//  * for a copy of the LGPLv3 License.
//  *
//  ************************************************************************/

#include <iostream>

#include <Titania/X3D.h>

#include "anyoption.h"

using namespace titania;

int
componentIndex ()
{
	auto browser = X3D::getBrowser ();

	browser -> setup ();

	const X3D::ComponentInfoArray & components = browser -> getSupportedComponents ();

	for (const auto & component : components)
	{
		std::cout << component -> getName () << std::endl;
	}

	return 0;
}

int
nodeIndex ()
{
	X3D::Generator::Style ("compact");

	for (const auto & node : X3D::getBrowser () -> getSupportedNodes ())
	{
		std::cout << '[' << node -> getTypeName () << ']' << std::endl;

		const X3D::FieldDefinitionArray & fieldDefinitions = node -> getFieldDefinitions ();

		for (const auto & fieldDefinition : fieldDefinitions)
		{
			const X3D::X3DFieldDefinition* field = node -> getField (fieldDefinition -> getName ());

			std::cout
				<< '\t'
				<< field -> getName () << " = "
				<< field -> getAliasName () << ";"
				<< X3D::Generator::AccessTypes [field] << ";"
				<< field -> getTypeName () << ";";

			if (field -> isInitializeable ())
				std::cout << field -> toString ();

			std::cout << std::endl;
		}

		std::cout << std::endl;
	}

	return 0;
}

int
x3d ()
{
	for (const auto & node : X3D::getBrowser () -> getSupportedNodes ())
		std::cout << node << std::endl;

	return 0;
}

int
main (int argc, char** argv)
{
	AnyOption options;

	options .addUsage ("SYNOPSIS");
	options .addUsage ("       titaniaInfo [-i=index]");
	options .addUsage ("");
	options .addUsage ("DESCRIPTION");
	options .addUsage ("       Format FILE, or standard input, to standard output");
	options .addUsage ("");
	options .addUsage ("       -i=index, --index=index");
	options .addUsage ("              index can be 'profile', 'component' or 'node'");
	options .addUsage ("              node is the default index");
	options .addUsage ("              profile: get a list of all supported profiles");
	options .addUsage ("              component: get a list of all supported components");
	options .addUsage ("              node: get a list of all supported nodes with it's associated fields");
	options .addUsage ("");
	options .addUsage ("       -x, --x3d");
	options .addUsage ("              get a list of all supported nodes in VRML style");
	options .addUsage ("");
	options .addUsage ("       -h, --help");
	options .addUsage ("              prints usage");

	options .setFlag   ("x3d",   'x');
	options .setFlag   ("index", 'i');
	options .setOption ("index", 'i');

	options .processCommandArgs (argc, argv);

	try
	{
		if (options .getValue ("index") or options .getValue ('i'))
		{
			std::string index = options .getValue ("index") ? options .getValue ("index") : options .getValue ('i');

			if (index == "profile")
				return componentIndex ();

			if (index == "component")
				return componentIndex ();

			if (index == "node")
				return nodeIndex ();
		}

		if (options .getFlag ("index") or options .getFlag ('i'))
			return nodeIndex ();

		if (options .getFlag ("x3d") or options .getFlag ('x'))
			return x3d ();

		options .printUsage ();

		return 0;
	}
	catch (const Glib::Exception & exception)
	{
		std::clog << exception .what () << std::endl;
	}
	catch (const std::exception & exception)
	{
		std::clog << exception .what () << std::endl;
	}
	catch (...)
	{
		std::clog << "Error: Unknown Exception." << std::endl;
	}

	return 1;
}