• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

Nepomuk-Core

  • sources
  • kde-4.12
  • kdelibs
  • nepomuk-core
  • rcgen
rcgen.cpp
Go to the documentation of this file.
1 /*
2  *
3  * $Id: sourceheader 511311 2006-02-19 14:51:05Z trueg $
4  *
5  * This file is part of the Nepomuk KDE project.
6  * Copyright (C) 2006-2009 Sebastian Trueg <trueg@kde.org>
7  *
8  * This library is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  * See the file "COPYING.LIB" for the exact licensing terms.
13  */
14 
15 #include <QtCore/QTextStream>
16 #include <QtCore/QFile>
17 #include <QtCore/QCoreApplication>
18 #include <QtCore/QRegExp>
19 
20 #include "kaboutdata.h"
21 #include "kcmdlineargs.h"
22 #include "kcomponentdata.h"
23 
24 #include "resourceclass.h"
25 #include "ontologyparser.h"
26 #include "codegenerator.h"
27 
28 
29 bool quiet = true;
30 
31 namespace {
35 QStringList extractOntologyFileList( const QStringList& args )
36 {
37  QStringList results;
38  foreach( const QString& a, args ) {
39  results << a.split( QRegExp("[\\s]") );
40  }
41  return results;
42 }
43 }
44 
45 int main( int argc, char** argv )
46 {
47  KAboutData aboutData( "nepomuk2-rcgen",
48  "nepomuk2-rcgen",
49  ki18n("Nepomuk2 Resource Class Generator"),
50  "0.3",
51  ki18n("Nepomuk2 Resource Class Generator"),
52  KAboutData::License_GPL,
53  ki18n("(c) 2006-2009, Sebastian Trüg"),
54  KLocalizedString(),
55  "http://nepomuk.kde.org" );
56  aboutData.addAuthor(ki18n("Sebastian Trüg"), ki18n("Maintainer"), "trueg@kde.org");
57  aboutData.addAuthor(ki18n("Tobias Koenig"), ki18n("Major cleanup - Personal hero of maintainer"), "tokoe@kde.org");
58  aboutData.addAuthor(ki18n("Vishesh Handa"), ki18n("Bug fixes and port to Nepomuk2"), "me@vhanda.in");
59  aboutData.setProgramIconName( "nepomuk" );
60  KComponentData component( aboutData );
61 
62  KCmdLineArgs::init( argc, argv, &aboutData );
63 
64  KCmdLineOptions options;
65  options.add("verbose", ki18n("Verbose output debugging mode."));
66  options.add("writeall", ki18n("Actually generate the code."));
67  options.add("listincludes", ki18n("List all includes (deprecated)."));
68  options.add("listheaders", ki18n("List all header files that will be generated via the --writeall command."));
69  options.add("listsources", ki18n("List all source files that will be generated via the --writeall command."));
70  options.add("ontologies <files>", ki18n("The ontology files containing the ontologies to be generated, a space separated list (deprecated: use arguments instead.)"));
71  options.add("prefix <prefix>", ki18n("Include path prefix (deprecated)"));
72  options.add("target <target-folder>", ki18n("Specify the target folder to store generated files into."));
73  // (romain_kdab) : watch out for a regression with --templates :
74  // KCmdLineOptions doesn't allow empty option arguments, so e.g. "--templates --foo" will treat --foo as the argument to --templates
75  // Since the option is deprecated it's probably not worth changing the KCmdLineOptions behaviour only for this ?
76  options.add("templates <templates>", ki18n("Templates to be used (deprecated)."));
77  options.add("class <classname>", ki18n("Optionally specify the classes to be generated. Use option multiple times (defaults to all classes)"));
78  options.add("serialization <rdf-serialization>", ki18n("Serialization used in the ontology files. Will default to primitive file extension detection."));
79  options.add("visibility <visibility-name>", ki18n("Set the used visibility in case the classes are to be used in public API. <visibility-name> will be used to construct the export macro name and the export header. By default classes will not be exported."));
80  options.add("+[ontologies]", ki18n("The ontology files containing the ontologies to be generated."));
81 
82  KCmdLineArgs::addCmdLineOptions( options );
83  QCoreApplication app( argc,argv );
84  KCmdLineArgs* args = KCmdLineArgs::parsedArgs();
85 
86 
87  // =====================================================
88  // prepare configuration
89  // =====================================================
90  bool writeAll = args->isSet("writeall");
91  bool listHeader = args->isSet("listheaders");
92  bool listSource = args->isSet("listsources");
93  bool listIncludes = args->isSet("listincludes");
94  quiet = !args->isSet("verbose");
95  QStringList ontoFiles = extractOntologyFileList( args->getOptionList("ontologies") ); // backwards comp
96  for(int i = 0; i < args->count(); ++i )
97  ontoFiles << args->arg(i);
98  QString targetDir = args->getOption("target");
99  QString prefix = args->getOption("prefix");
100  QStringList templates = args->getOptionList("templates");
101  QStringList classesToGenerate = args->getOptionList( "class" );
102  QString visibility = args->getOption("visibility");
103 
104  // =====================================================
105  // a few checks for valid parameters (not complete!)
106  // =====================================================
107  if( ontoFiles.isEmpty() ) {
108  QTextStream s( stderr );
109  s << "No ontology files specified." << endl;
110  return -1;
111  }
112 
113  foreach( const QString& ontoFile, ontoFiles ) {
114  if( !QFile::exists( ontoFile ) ) {
115  QTextStream s( stderr );
116  s << "Ontology file " << ontoFile << " does not exist." << endl;
117  return -1;
118  }
119  }
120 
121  if( writeAll ) {
122  if( !QFile::exists( targetDir ) ) {
123  QTextStream s( stderr );
124  s << "Folder " << targetDir << " does not exist." << endl;
125  return -1;
126  }
127  }
128 
129 
130  // =====================================================
131  // parse the data and determine the classes to generate
132  // =====================================================
133  OntologyParser prsr;
134  foreach( const QString& ontoFile, ontoFiles ) {
135  if( !prsr.parse( ontoFile, args->getOption("serialization") ) ) {
136  QTextStream s( stderr );
137  s << "Parsing ontology file " << ontoFile << " failed." << endl;
138  return -1;
139  }
140  }
141 
142  // if classes to be generated have been specified on the command line, reset all ResourceClass
143  // instances in terms of generation
144  if( !classesToGenerate.isEmpty() ) {
145  foreach( ResourceClass* rc, prsr.parsedClasses() ) {
146  rc->setGenerateClass( classesToGenerate.contains( rc->uri().toString() ) );
147  }
148  }
149 
150 
151  // =====================================================
152  // create the code generator which will take care of the rest
153  // =====================================================
154  CodeGenerator codeGen( CodeGenerator::SafeMode, prsr.parsedClasses() );
155  codeGen.setVisibility( visibility );
156 
157  if( writeAll ) {
158  if( !codeGen.writeSources( targetDir ) ) {
159  QTextStream s( stderr );
160  s << "Writing sources to " << targetDir << " failed." << endl;
161  return -1;
162  }
163  }
164  else if( listSource ) {
165  QStringList l = codeGen.listSources();
166  QTextStream s( stdout, QIODevice::WriteOnly );
167  QStringListIterator it( l );
168  while( it.hasNext() )
169  s << prefix << it.next() << ";";
170  }
171  else if( listHeader ) {
172  QStringList l = codeGen.listHeader();
173  QTextStream s( stdout, QIODevice::WriteOnly );
174  QStringListIterator it( l );
175  while( it.hasNext() )
176  s << prefix << it.next() << ";";
177  }
178  else if( listIncludes ) {
179  QStringList l = codeGen.listHeader();
180  QTextStream s( stdout, QIODevice::WriteOnly );
181  QStringListIterator it( l );
182  while( it.hasNext() )
183  s << "#include <nepomuk2/" << it.next() << ">" << endl;
184  }
185 
186  return 0;
187 }
resourceclass.h
CodeGenerator::setVisibility
void setVisibility(const QString &v)
Definition: codegenerator.h:36
ResourceClass::uri
QUrl uri() const
Returns the uri of the resource.
Definition: resourceclass.cpp:43
OntologyParser
Definition: ontologyparser.h:23
ontologyparser.h
OntologyParser::parse
bool parse(const QString &filename, const QString &serialization=QString())
Definition: ontologyparser.cpp:105
codegenerator.h
ResourceClass
Represents a resource.
Definition: resourceclass.h:30
OntologyParser::parsedClasses
QList< ResourceClass * > parsedClasses() const
Definition: ontologyparser.cpp:232
ResourceClass::setGenerateClass
void setGenerateClass(bool generate)
Sets whether code for this class shall be generated.
Definition: resourceclass.cpp:112
CodeGenerator
Definition: codegenerator.h:26
main
int main(int argc, char **argv)
Definition: rcgen.cpp:45
CodeGenerator::SafeMode
Definition: codegenerator.h:30
quiet
bool quiet
Definition: rcgen.cpp:29
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:48:08 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Nepomuk-Core

Skip menu "Nepomuk-Core"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal