1
/* This file is part of KDevelop
2
Copyright (C) 2003 Roberto Raggi <roberto@kdevelop.org>
3
Copyright (C) 2004 Matt Rogers <mattr@kde.org>
4
Copyright (C) 2004 Alexander Dymo <adymo@kdevelop.org>
6
This library is free software; you can redistribute it and/or
7
modify it under the terms of the GNU Library General Public
8
License as published by the Free Software Foundation; either
9
version 2 of the License, or (at your option) any later version.
11
This library is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
Library General Public License for more details.
16
You should have received a copy of the GNU Library General Public License
17
along with this library; see the file COPYING.LIB. If not, write to
18
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19
Boston, MA 02111-1307, USA.
26
Code Model - a memory symbol store.
30
#include <qstringlist.h>
31
#include <ksharedptr.h>
39
class FunctionDefinitionModel;
43
class EnumeratorModel;
47
Safe pointer to the @ref CodeModelItem.
48
This is a type definition: @code typedef KSharedPtr<CodeModelItem> ItemDom; @endcode
50
typedef KSharedPtr<CodeModelItem> ItemDom;
52
Safe pointer to the @ref FileModel.
53
This is a type definition: @code typedef KSharedPtr<FileModel> FileDom; @endcode
55
typedef KSharedPtr<FileModel> FileDom;
56
/**@class NamespaceDom
57
Safe pointer to the @ref NamespaceModel.
58
This is a type definition: @code typedef KSharedPtr<NamespaceModel> NamespaceDom; @endcode
60
typedef KSharedPtr<NamespaceModel> NamespaceDom;
62
Safe pointer to the @ref ClassModel.
63
This is a type definition: @code typedef KSharedPtr<ClassModel> ClassDom; @endcode
65
typedef KSharedPtr<ClassModel> ClassDom;
67
Safe pointer to the @ref FunctionModel.
68
This is a type definition: @code typedef KSharedPtr<FunctionModel> FunctionDom; @endcode
70
typedef KSharedPtr<FunctionModel> FunctionDom;
71
/**@class FunctionDefinitionDom
72
Safe pointer to the @ref FunctionDefinitionModel.
73
This is a type definition: @code typedef KSharedPtr<FunctionDefinitionModel> FunctionDefinitionDom; @endcode
75
typedef KSharedPtr<FunctionDefinitionModel> FunctionDefinitionDom;
77
Safe pointer to the @ref VariableModel.
78
This is a type definition: @code typedef KSharedPtr<VariableModel> VariableDom; @endcode
80
typedef KSharedPtr<VariableModel> VariableDom;
82
Safe pointer to the @ref ArgumentModel.
83
This is a type definition: @code typedef KSharedPtr<ArgumentModel> ArgumentDom; @endcode
85
typedef KSharedPtr<ArgumentModel> ArgumentDom;
87
Safe pointer to the @ref EnumModel.
88
This is a type definition: @code typedef KSharedPtr<EnumModel> EnumDom; @endcode
90
typedef KSharedPtr<EnumModel> EnumDom;
91
/**@class TypeAliasDom
92
Safe pointer to the @ref TypeAliasModel.
93
This is a type definition: @code typedef KSharedPtr<TypeAliasModel> TypeAliasDom; @endcode
95
typedef KSharedPtr<TypeAliasModel> TypeAliasDom;
96
/**@class EnumeratorDom
97
Safe pointer to the @ref EnumeratorModel.
98
This is a type definition: @code typedef KSharedPtr<EnumeratorModel> EnumeratorDom; @endcode
100
typedef KSharedPtr<EnumeratorModel> EnumeratorDom;
103
The list of code model items.
104
This is a type definition: @code typedef QValueList<ItemDom> ItemList; @endcode
106
typedef QValueList<ItemDom> ItemList;
108
The list of code model files.
109
This is a type definition: @code typedef QValueList<FileDom> FileList; @endcode
111
typedef QValueList<FileDom> FileList;
112
/**@class NamespaceList
113
The list of code model namespaces.
114
This is a type definition: @code typedef QValueList<NamespaceDom> NamespaceList; @endcode
116
typedef QValueList<NamespaceDom> NamespaceList;
118
The list of code model classes.
119
This is a type definition: @code typedef QValueList<ClassDom> ClassList; @endcode
121
typedef QValueList<ClassDom> ClassList;
122
/**@class FunctionList
123
The list of code model functions.
124
This is a type definition: @code typedef QValueList<FunctionDom> FunctionList; @endcode
126
typedef QValueList<FunctionDom> FunctionList;
127
/**@class FunctionDefinitionList
128
The list of code model function definitions.
129
This is a type definition: @code typedef QValueList<FunctionDefinitionDom> FunctionDefinitionList; @endcode
131
typedef QValueList<FunctionDefinitionDom> FunctionDefinitionList;
132
/**@class VariableList
133
The list of code model variables.
134
This is a type definition: @code typedef QValueList<VariableDom> VariableList; @endcode
136
typedef QValueList<VariableDom> VariableList;
137
/**@class ArgumentList
138
The list of code model arguments.
139
This is a type definition: @code typedef QValueList<ArgumentDom> ArgumentList; @endcode
141
typedef QValueList<ArgumentDom> ArgumentList;
143
The list of code model enums.
144
This is a type definition: @code typedef QValueList<EnumDom> EnumList; @endcode
146
typedef QValueList<EnumDom> EnumList;
147
/**@class TypeAliasList
148
The list of code model type aliases.
149
This is a type definition: @code typedef QValueList<TypeAliasDom> TypeAliasList; @endcode
151
typedef QValueList<TypeAliasDom> TypeAliasList;
152
/**@class EnumeratorList
153
The list of code model enumerators.
154
This is a type definition: @code typedef QValueList<EnumeratorDom> EnumeratorList; @endcode
156
typedef QValueList<EnumeratorDom> EnumeratorList;
158
/**Iterates through @p lst and creates sorted list of code model item names.
159
Can be used, for example, to get the list of classes in the store:
161
QStringList classList = sortedNameList(codeModel()->globalNamespace()->classList());
163
@param lst The list to iterate.
164
@return Sorted list of code model item names.*/
165
template <class ItemList>
166
QStringList sortedNameList( const ItemList& lst )
168
QStringList nameList;
170
typename ItemList::ConstIterator it = lst.begin();
171
while( it != lst.end() ){
172
if( !(*it)->name().isEmpty() )
173
nameList << (*it)->name();
181
/**Casts safe code model pointers (@p KSharedPtr<T> objects like
182
FileDom, NamespaceDom, etc.) to the @p Result type.
186
//ns is of type NamespaceDom
187
ClassDom cl = model_cast<ClassDom>(ns);
189
@param x Object to cast.*/
190
template <class Result, class T>
191
Result model_cast( KSharedPtr<T> x )
193
Result r( static_cast<T*>(x) );
197
/**Casts code model pointers (objects like
198
FileModel, NamespaceModel, etc.) to the @p Result type.
202
//ns is of type NamespaceModel*
203
ClassDom cl = model_cast<ClassDom>(ns);
205
@param x Object to cast.*/
206
template <class Result, class T>
207
Result model_cast( T* x )
209
Result r( static_cast<T*>(x) );
215
Code Model - a memory symbol store.
216
Symbol store (aka class store) is a database of symbols
217
found in code with the important information about those symbols.
219
For example, programming language support plugins use symbol store
220
to remember information about classes, functions, etc. For each type
221
of symbol a certain information can be stored - symbol name, the
222
location in source file, etc.
224
@sa codemodel.h documentation for a list of typedefs and other convenience functions.
226
@sa codemodel_utils.h documentation for an additional code model utility functions and classes reference.
234
virtual ~CodeModel();
236
/**Creates a code model item. This should be used to create
239
For example, to create a class model somewhere in your plugin, use:
241
klass = codeModel()->create<ClassModel>();
242
klass->setName("ClassName");
243
klass->setFileName("FileName");
244
klass->setStartPosition(line, column);
246
@return Created code model item.*/
247
template <class T> typename T::Ptr create()
249
typename T::Ptr ptr( new T(this) );
253
/**Resets the CodeModel.*/
256
/**Gets the list of files in the store.
257
@return The FileList object that contains the list of files.*/
260
/**Gets the list of files in the store.
261
This is a const version for convenience.
262
@return The FileList object that contains the list of files.*/
263
const FileList fileList() const;
265
/**Checks to see if a file is in the store.
266
@return true if @p name is in the file list.*/
267
bool hasFile( const QString& name ) const;
269
/**Gets the FileDom object for a file.
270
@param name The name of the file to get the FileDom object for.*/
271
FileDom fileByName( const QString& name );
273
/**Gets the FileDom object for a file.
274
This is a const version provided for convenience.
275
@param name the name of the file to get the FileDom object for.*/
276
const FileDom fileByName( const QString& name ) const;
278
/**Adds a file to the store.
279
@param file The FileDom object to add to the store.
280
@return true if the file was added successfully.*/
281
bool addFile( FileDom file );
283
/**Removes a file from the store.
284
@param file the FileDom object to remove from the store.*/
285
void removeFile( FileDom file );
287
/**Gets the global namespace
288
@return The NamespaceDom object that represents the global namespace.*/
289
const NamespaceDom globalNamespace() const;
291
/**Reads the model from a stream.
292
Use this to save the memory symbol store to a file.
294
Language support plugins usually save symbols from projects before the project is
295
closed to avoid reparsing when the project is opened next time.
296
@param stream Stream to read from.*/
297
virtual void read( QDataStream& stream );
298
/**Writes the model to a stream.
299
Use this to restore the memory symbol store to a file.
301
Language support plugins usually save symbols from projects before the project is
302
closed to avoid reparsing when the project is opened next time.
303
@param stream Stream to write to.*/
304
virtual void write( QDataStream& stream ) const;
307
/**Adds a namespace to the store.
308
@param target The NamespaceDom object that the namespace will be added to.
309
@param source The NamespaceDom object that contains the namespace to remove.*/
310
void addNamespace( NamespaceDom target, NamespaceDom source );
312
/**Removes a namespace from the store.
313
@param target The NamespaceDom object that the namespace will be removed from.
314
@param source The NamespaceDom object that contains the namespace to remove.*/
315
void removeNamespace( NamespaceDom target, NamespaceDom source );
318
QMap<QString, FileDom> m_files;
319
NamespaceDom m_globalNamespace;
322
CodeModel( const CodeModel& source );
323
void operator = ( const CodeModel& source );
324
friend class CodeModelItem;
329
Item in code model (symbol store).
330
Item is a symbol in a store. Code model provides several predefined classes
331
for predefined item types (files, namespaces, classes, functions and function definitions,
332
variables, arguments, enums and enumerators, type aliases.
334
Instanses of this class should be created using @ref CodeModel::create method but usually
335
it is better to create instances of derived classes like ClassModel, NamespaceModel, FileModel, etc.
337
class CodeModelItem: public KShared
340
/**A definition of safe pointer to the code model item.*/
343
/**A type of a code model item.*/
347
Namespace, /**<Namespace.*/
349
Function, /**<Function or class method.*/
350
Variable, /**<Variable.*/
351
Argument, /**<Function or method parameter.*/
352
FunctionDefinition, /**<Function definition.*/
354
Enumerator, /**<Enumerator - a member of an Enum (example: @code enum Type { A, B, C} @endcode
355
Type will be an Enum; A, B and C - Enumerators.*/
356
TypeAlias, /**<Type alias (aka typedef in c++).*/
358
Custom = 1000 /**<Custom model items should have type greater than 1000*/
361
/**An access to the code model item.*/
364
Public, /**<Public.*/
365
Protected, /**<Protected.*/
366
Private /**<Private.*/
371
@param kind The type, see also @ref CodeModelItem::Kind.
372
@param model Code model which stores this item.*/
373
CodeModelItem( int kind, CodeModel* model );
377
virtual ~CodeModelItem();
379
/**@return The type (kind) of item.*/
380
int kind() const { return m_kind; }
382
/**Sets the type (kind) of item.
383
@param kind The type, see also @ref CodeModelItem::Kind.*/
384
void setKind( int kind ) { m_kind = kind; }
386
/**@return The name of the item.*/
387
QString name() const;
389
/**Sets the name of the item.
390
@param name The name.*/
391
void setName( const QString& name );
393
/**Gets the file of the item.
394
@return The FileDom object for the item.*/
397
/**Gets the file of the item
398
This is a const version provided for convenience.
399
@return The FileDom object for the item.*/
400
const FileDom file() const;
402
/**@return The filename of the item.*/
403
QString fileName() const;
405
/**Sets the filename of the item.
406
@param fileName The file name.*/
407
void setFileName( const QString& fileName );
409
/**Gets the start position of the item.
410
@param line Will be set to the line number of the items start position. Pass 0 if line number is not necessary.
411
@param col Will be set to the column number of the items start position. Pass 0 if column number is not necessary.*/
412
void getStartPosition( int* line, int* col ) const;
414
/**Sets the start position of the item.
415
@param line Line number.
416
@param col Column number.*/
417
void setStartPosition( int line, int col );
419
/**Get the end position of the item.
420
@param line Will be set to the line number of the items end position. Pass 0 if line number is not necessary.
421
@param col Will be set to the column number of the items end position. Pass 0 if column number is not necessary.*/
422
void getEndPosition( int* line, int* col ) const;
424
/**Set the end position of the item.
425
@param line Line number.
426
@param col Column number.*/
427
void setEndPosition( int line, int col );
429
/**@return true if an item is a FileModel.*/
430
virtual bool isFile() const { return false; }
431
/**@return true if an item is a NamespaceModel.*/
432
virtual bool isNamespace() const { return false; }
433
/**@return true if an item is a ClassModel.*/
434
virtual bool isClass() const { return false; }
435
/**@return true if an item is a FunctionModel.*/
436
virtual bool isFunction() const { return false; }
437
/**@return true if an item is a FileDefinitionModel.*/
438
virtual bool isFunctionDefinition() const { return false; }
439
/**@return true if an item is a VariableModel.*/
440
virtual bool isVariable() const { return false; }
441
/**@return true if an item is an ArgumentModel.*/
442
virtual bool isArgument() const { return false; }
443
/**@return true if an item is a EnumModel.*/
444
virtual bool isEnum() const { return false; }
445
/**@return true if an item is a EnumeratorModel.*/
446
virtual bool isEnumerator() const { return false; }
447
/**@return true if an item is a TypeAliasModel.*/
448
virtual bool isTypeAlias() const { return false; }
449
/**@return true if an item is a custom item.*/
450
virtual bool isCustom() const { return false; }
452
/**Reads an item from the stream.
453
@param stream The stream to read from.*/
454
virtual void read( QDataStream& stream );
455
/**Writes an item to the stream.
456
@param stream The stream to write to.*/
457
virtual void write( QDataStream& stream ) const;
461
/**@return The code model for this item.*/
462
CodeModel* codeModel() { return m_model; }
464
/**@note This is a const version provided for convenience.
465
@return The code model for this item*/
466
const CodeModel* codeModel() const { return m_model; }
473
int m_startLine, m_startColumn;
474
int m_endLine, m_endColumn;
477
CodeModelItem( const CodeModelItem& source );
478
void operator = ( const CodeModelItem& source );
484
Represents a class in the code model.
486
Instanses of this class should be created using @ref CodeModel::create method.
488
class ClassModel: public CodeModelItem
492
@param model Code model which stores this item.*/
493
ClassModel( CodeModel* model );
496
/**A definition of safe pointer to the class model.*/
497
typedef ClassDom Ptr;
499
virtual bool isClass() const { return true; }
501
/**@return The scope of the class. Scope is a string list composed from names of parent classes and namespaces.*/
502
QStringList scope() const { return m_scope; }
503
/**Sets the scope of this class.
504
@param scope The scope - a list of parent classes and namespaces.*/
505
void setScope( const QStringList& scope ) { m_scope = scope; }
507
/**@return The list of base class names.*/
508
QStringList baseClassList() const;
510
/**Adds a base class to the list of base classes.
511
@param baseClass The base class name.*/
512
bool addBaseClass( const QString& baseClass );
514
/**Removes a base class from the list of base classes.
515
@param baseClass The base class name.*/
516
void removeBaseClass( const QString& baseClass );
518
/**@return The list of (sub)classes in this model.*/
519
ClassList classList();
521
/**@note This is a const version provided for convenience.
522
@return The list of (sub)classes in this model.*/
523
const ClassList classList() const;
525
/**Checks if the class specified by @p name is in this model.
526
@param name The name of a class to look for.
527
@return true if the model has a class.*/
528
bool hasClass( const QString& name ) const;
530
/**@param name The name of a class.
531
@return A list of classes that match the name given by @p name.*/
532
ClassList classByName( const QString& name );
534
/**@param name The name of a class.
535
@return A list of classes that match the name given by @p name.
536
@note This is a const version provided for convenience.*/
537
const ClassList classByName( const QString& name ) const;
539
/**Adds a class to the model.
540
@param klass The class model to add.
541
@return true if addition was successful.*/
542
bool addClass( ClassDom klass );
544
/**Removes a class from the model.
545
@param klass The class model to remove.*/
546
void removeClass( ClassDom klass );
548
/**@return A list of functions in the model.*/
549
FunctionList functionList();
551
/**@return A list of functions in the model.
552
@note This is a const version provided for convenience.*/
553
const FunctionList functionList() const;
555
/**Check if the function specified by @p name is in the model.
556
@param name The name of a function to look for.
557
@return true if the model has a class.*/
558
bool hasFunction( const QString& name ) const;
560
/**@param name The name of a function to look for.
561
@return A list of functions that match the name given by @p name.*/
562
FunctionList functionByName( const QString& name );
564
/**@param name The name of a function to look for.
565
@return A list of functions that match the name given by @p name.
566
@note This is a const version provided for convenience.*/
567
const FunctionList functionByName( const QString& name ) const;
569
/**Adds a function to the class model.
570
@param fun The function model to add.
571
@return true if addition was successful.*/
572
bool addFunction( FunctionDom fun );
574
/**Removes a function from the class model.
575
@param fun The FunctionDom object to remove from the model.*/
576
void removeFunction( FunctionDom fun );
578
/**@return The list of function definitions in the model.*/
579
FunctionDefinitionList functionDefinitionList();
581
/**@return The list of function definitions
582
@note This is a const version provided for convenience.*/
583
const FunctionDefinitionList functionDefinitionList() const;
585
/**Checks if the function definition specified by \p name is in the model.
586
@param name The name of a function definition to look for.
587
@return true if the function definition was found.*/
588
bool hasFunctionDefinition( const QString& name ) const;
590
/**Gets the list of functions that match the name given by \p name.
591
If there are no matches, then the list returned is empty.
592
@param name The name of a function definition to look for.
593
@return The FunctionDefinitionList object containing the definitions that match.*/
594
FunctionDefinitionList functionDefinitionByName( const QString& name );
596
/**Gets the list of functions that match the name given by \p name.
597
If there are no matches, then the list returned is empty.
598
@param name The name of a function definition to look for.
599
@return The FunctionDefinitionList object containing the definitions that match.
600
@note This is a const version provided for convenience.*/
601
const FunctionDefinitionList functionDefinitionByName( const QString& name ) const;
603
/**Adds a function definition to the model.
604
@param fun The function fefinition model to add to the model.
605
@return true if the addition was successful.*/
606
bool addFunctionDefinition( FunctionDefinitionDom fun );
608
/**Removes a function definition from the model.
609
@param fun The function fefinition model to remove from the model.*/
610
void removeFunctionDefinition( FunctionDefinitionDom fun );
612
/**@return The list of variables in the model.*/
613
VariableList variableList();
615
/**@return The list of variables in the model.
616
@note This is a const version provided for convenience.*/
617
const VariableList variableList() const;
619
/**Checks if the variable specified by @p name is in the model.
620
@param name The name of a variable.
621
@return true if the variable was found.*/
622
bool hasVariable( const QString& name ) const;
624
/**Gets the variable specified by @p name.
625
If there are no matches, then the VariableDom object returned is empty.
626
@param name The name of a variable.
627
@return A VariableDom object that matches the name specified.*/
628
VariableDom variableByName( const QString& name );
630
/**Gets the variable specified by @p name.
631
If there are no matches, then the VariableDom object returned is empty.
632
@param name The name of a variable.
633
@return A VariableDom object that matches the name specified.
634
@note This is a const version provided for convenience.*/
635
const VariableDom variableByName( const QString& name ) const;
637
/**Adds a variable to the model.
638
@param var The variable model to add to the model.
639
@return true if the addition was successful.*/
640
bool addVariable( VariableDom var );
642
/**Removes a variable from the model.
643
@param var The variable model to remove from the model.*/
644
void removeVariable( VariableDom var );
646
/**@return The type alias list for this model.*/
647
TypeAliasList typeAliasList();
649
/**@return The type alias list for this model.
650
@note This is a const version provided for convenience.*/
651
const TypeAliasList typeAliasList() const;
653
/**Checks if the type alias specified by @p name is in the model.
654
@param name The name of a type alias.
655
@return true if the type alias was found.*/
656
bool hasTypeAlias( const QString& name ) const;
658
/**Gets the list of type aliases that match @p name.
659
If there are no matches, the TypeAliasList object is empty.
660
@param name The name of a type alias.
661
@return A TypeAliasList object that contains the matches.*/
662
TypeAliasList typeAliasByName( const QString& name );
664
/**Gets the list of type aliases that match @p name.
665
If there are no matches, the TypeAliasList object is empty.
666
@param name The name of a type alias.
667
@return A TypeAliasList object that contains the matches.
668
@note This is a const version provided for convenience.*/
669
const TypeAliasList typeAliasByName( const QString& name ) const;
671
/**Adds a type alias to the model.
672
@param typeAlias The type alias model to add to the model.
673
@return true if the addition was successful.*/
674
bool addTypeAlias( TypeAliasDom typeAlias );
676
/**Removes a type alias from the model.
677
@param typeAlias The TypeAliasDom object to remove from the model.*/
678
void removeTypeAlias( TypeAliasDom typeAlias );
680
/**@return The list of enums in the model.*/
683
/**@return The list of enums in the model.
684
@note This is a const version provided for convenience.*/
685
const EnumList enumList() const;
687
/**Checks if the enum specified by @p name is in the model.
688
@param name The name of an enum.
689
@return true if the enum was found.*/
690
bool hasEnum( const QString& name ) const;
692
/**Gets the enum specified by @p name.
693
The EnumDom object returned will be empty if no match is found.
694
@param name The name of an enum.
695
@return The EnumDom object that contains the match.*/
696
EnumDom enumByName( const QString& name );
698
/**Gets the enum specified by @p name.
699
The EnumDom object returned will be empty if no match is found.
700
@param name The name of an enum.
701
@return The EnumDom object that contains the match.*/
702
const EnumDom enumByName( const QString& name ) const;
704
/**Adds an enum to the model.
705
@param e The enum model to add to the model.
706
@return true if the addition was successful.*/
707
bool addEnum( EnumDom e );
709
/**Removes an enum from the model.
710
@param e The enum model to remove from the model.*/
711
void removeEnum( EnumDom e );
713
virtual void read( QDataStream& stream );
714
virtual void write( QDataStream& stream ) const;
718
QStringList m_baseClassList;
719
QMap<QString, ClassList> m_classes;
720
QMap<QString, FunctionList> m_functions;
721
QMap<QString, FunctionDefinitionList> m_functionDefinitions;
722
QMap<QString, VariableDom> m_variables;
723
QMap<QString, TypeAliasList> m_typeAliases;
724
QMap<QString, EnumDom> m_enumerators;
727
ClassModel( const ClassModel& source );
728
void operator = ( const ClassModel& source );
729
friend class CodeModel;
735
Represents a namespace in the code model.
736
Namespace model can represent either usual c++ namespaces
737
and packages or modules from other languages.
739
Instanses of this class should be created using @ref CodeModel::create method.
741
class NamespaceModel: public ClassModel
745
@param model Code model which stores this item.*/
746
NamespaceModel( CodeModel* model );
749
/**A definition of safe pointer to the namespace model.*/
750
typedef NamespaceDom Ptr;
752
virtual bool isClass() const { return false; }
753
virtual bool isNamespace() const { return true; }
755
/**@return The list of namespaces in this model.*/
756
NamespaceList namespaceList();
758
/**@return The list of namespaces in this model.
759
@note This is a const version provided for convenience.*/
760
const NamespaceList namespaceList() const;
762
/**Checks if the namespace referenced by @p name is in the model.
763
@param name The name of a namespace.
764
@return true if the namespace was found.*/
765
bool hasNamespace( const QString& name ) const;
767
/**Gets the namespace specified by @p name.
768
If there are no matches, then the NamespaceDom object returned is empty.
769
@param name The name of a namespace.
770
@return The NamespaceDom object that contains the match.*/
771
NamespaceDom namespaceByName( const QString& name );
773
/**Gets the namespace specified by @p name.
774
If there are no matches, then the NamespaceDom object returned is empty.
775
@param name The name of a namespace.
776
@return The NamespaceDom object that contains the match.
777
@note This is a const version provided for convenience.*/
778
const NamespaceDom namespaceByName( const QString& name ) const;
780
/**Adds a namespace to the model.
781
@param ns The namespace model to add to the model.
782
@return true if addition was successful.*/
783
bool addNamespace( NamespaceDom ns );
785
/**Removes the namespace from the model.
786
@param ns The namespace model to remove from the model.*/
787
void removeNamespace( NamespaceDom ns );
789
virtual void read( QDataStream& stream );
790
virtual void write( QDataStream& stream ) const;
793
QMap<QString, NamespaceDom> m_namespaces;
796
NamespaceModel( const NamespaceModel& source );
797
void operator = ( const NamespaceModel& source );
798
friend class CodeModel;
805
Represents a file in the code model.
806
Files in general contain classes, namespaces, functions,
807
types, etc. Therefore FileModel is derived from NamespaceModel.
809
Instanses of this class should be created using @ref CodeModel::create method.
811
class FileModel: public NamespaceModel
815
@param model Code model which stores this item.*/
816
FileModel( CodeModel* model );
819
/**A definition of safe pointer to the file model.*/
822
virtual bool isFile() const { return true; }
824
virtual void read( QDataStream& stream );
825
virtual void write( QDataStream& stream ) const;
828
FileModel( const FileModel& );
829
void operator = ( const FileModel& );
830
friend class CodeModel;
835
Function (procedure) argument model.
836
Represents an argument in the function.
838
Instanses of this class should be created using @ref CodeModel::create method.
840
class ArgumentModel: public CodeModelItem
843
ArgumentModel( CodeModel* model );
846
/**A definition of safe pointer to the argument model.*/
847
typedef ArgumentDom Ptr;
849
virtual bool isArgument() const { return true; }
851
/**@return The type of this argument.*/
852
QString type() const;
854
/**Sets the type of this argument.
855
@param type The type to set.*/
856
void setType( const QString& type );
858
/**@return The default value of this argument.*/
859
QString defaultValue() const;
861
/**Sets the default value of this argument.
862
@param defaultValue The default value to set.*/
863
void setDefaultValue( const QString& defaultValue );
865
virtual void read( QDataStream& stream );
866
virtual void write( QDataStream& stream ) const;
870
QString m_defaultValue;
873
ArgumentModel( const ArgumentModel& source );
874
void operator = ( const ArgumentModel& source );
875
friend class CodeModel;
886
In languages that have separate function declarations and definitions (c++)
887
this represents only function declarations. @see FunctionDefinitionModel
888
for a model of function definitions.
890
Instanses of this class should be created using @ref CodeModel::create method.
892
class FunctionModel: public CodeModelItem
896
@param model Code model which stores this item.*/
897
FunctionModel( CodeModel* model );
900
/**A definition of safe pointer to the function model.*/
901
typedef FunctionDom Ptr;
903
virtual bool isFunction() const { return true; }
905
/**@return The scope of the function. Scope is a string list composed
906
from names of parent functions, classes and namespaces.*/
907
QStringList scope() const { return m_scope; }
909
/**Sets the scope of the function.
910
@param scope The scope to set.*/
911
void setScope( const QStringList& scope ) { m_scope = scope; }
913
/**@return The access level of the function. Can return either values of type @ref CodeModelItem::Access or
914
other integers if the function has other access level (for example pascal methods can have "published"
918
/**Sets the access level of the function.
919
@param access The access level.*/
920
void setAccess( int access );
922
/**@return true if the function is a signal.*/
923
bool isSignal() const;
924
/**Sets the function to be a signal.
925
@param isSignal The signal flag.*/
926
void setSignal( bool isSignal );
928
/**@return true if the function is a slot.*/
930
/**Sets the function to be a slot.
931
@param isSlot The slot flag.*/
932
void setSlot( bool isSlot );
934
/**@return true if the function is a virtual function.*/
935
bool isVirtual() const;
936
/**Sets the function to be a virtual function.
937
@param isVirtual The virtual flag.*/
938
void setVirtual( bool isVirtual );
940
/**@return true if the function is a static function.*/
941
bool isStatic() const;
942
/**Sets the function to be a static function.
943
@param isStatic The static flag.*/
944
void setStatic( bool isStatic );
946
/**@return true if the function is an inline function.*/
947
bool isInline() const;
948
/**Sets the function to be an inline function.
949
@param isInline The inline flag.*/
950
void setInline( bool isInline );
952
/**@return true if the function is a constant function.*/
953
bool isConstant() const;
954
/**Sets the function to be a constant function.
955
@param isConstant The constant flag.*/
956
void setConstant( bool isConstant );
958
/**@return true if the function is an abstract function.*/
959
bool isAbstract() const;
960
/**Sets the function to be an inline function.
961
@param isAbstract The abstract flag.*/
962
void setAbstract( bool isAbstract );
964
/**@return The result type of a function.*/
965
QString resultType() const;
966
/**Sets the result type of a function.
967
@param type The type of a function result.*/
968
void setResultType( const QString& type );
970
/**Gets the list of arguments being passed to the function.
971
If there are no arguments, then the list is empty.
972
@return The ArgumentList object that contains the arguments for this function.*/
973
ArgumentList argumentList();
975
/**Gets the list of arguments being passed to the function.
976
If there are no arguments, then the list is empty.
977
@return The ArgumentList object that contains the arguments for this function.
978
@note This is a const version provided for convenience.*/
979
const ArgumentList argumentList() const;
981
/**Adds an argument to the function.
982
@param arg The argument model to add as an argument to the function.
983
@return true if the addition was successful.*/
984
bool addArgument( ArgumentDom arg );
986
/**Removes an argument from the function.
987
@param arg The argument model to remove from the function.*/
988
void removeArgument( ArgumentDom arg );
990
virtual void read( QDataStream& stream );
991
virtual void write( QDataStream& stream ) const;
1010
QString m_resultType;
1011
ArgumentList m_arguments;
1014
FunctionModel( const FunctionModel& source );
1015
void operator = ( const FunctionModel& source );
1016
friend class CodeModel;
1021
Represents function definition for languages that have such.
1023
Instanses of this class should be created using @ref CodeModel::create method.
1025
class FunctionDefinitionModel: public FunctionModel
1029
@param model Code model which stores this item.*/
1030
FunctionDefinitionModel( CodeModel* model );
1033
/**A definition of safe pointer to the function definition model.*/
1034
typedef FunctionDefinitionDom Ptr;
1036
virtual bool isFunctionDefinition() const { return true; }
1039
FunctionDefinitionModel( const FunctionDefinitionModel& source );
1040
void operator = ( const FunctionDefinitionModel& source );
1041
friend class CodeModel;
1047
Represents variables and class attributes.
1049
Instanses of this class should be created using @ref CodeModel::create method.
1051
class VariableModel: public CodeModelItem
1055
@param model Code model which stores this item.*/
1056
VariableModel( CodeModel* model );
1059
/**A definition of safe pointer to the variable model.*/
1060
typedef VariableDom Ptr;
1062
virtual bool isVariable() const { return true; }
1064
/**@return The access level of the variable. Can return either values of type @ref CodeModelItem::Access or
1065
other integers if the variable has other access level (for example pascal attributes can have "published"
1068
/**Sets the access level of the variable.
1069
@param access The access level.*/
1070
void setAccess( int access );
1072
/**@return true if the variable is a static variable.*/
1073
bool isStatic() const;
1074
/**Sets the variable to be a static variable.
1075
@param isStatic The static flag.*/
1076
void setStatic( bool isStatic );
1078
/**@return A type of the variable.*/
1079
QString type() const;
1080
/**Sets the type of the variable.
1081
@param type The type name.*/
1082
void setType( const QString& type );
1084
virtual void read( QDataStream& stream );
1085
virtual void write( QDataStream& stream ) const;
1093
VariableModel( const VariableModel& source );
1094
void operator = ( const VariableModel& source );
1095
friend class CodeModel;
1103
Instanses of this class should be created using @ref CodeModel::create method.
1105
class EnumModel: public CodeModelItem
1109
@param model Code model which stores this item.*/
1110
EnumModel( CodeModel* model );
1113
/**A definition of safe pointer to the enum model.*/
1114
typedef EnumDom Ptr;
1116
virtual bool isEnum() const { return true; }
1118
/**@return The access level of the enum. Can return either values
1119
of type @ref CodeModelItem::Access or other integers if the enum has other access level.*/
1121
/**Sets the access level of the enum.
1122
@param access The access level.*/
1123
void setAccess( int access );
1125
/**@return The list of enumerators in this enum.*/
1126
EnumeratorList enumeratorList();
1127
/**@return The list of enumerators in this enum.
1128
@note This is a const version provided for convenience.*/
1129
const EnumeratorList enumeratorList() const;
1130
/**Adds an enumerator to the model.
1131
@param e The enumerator model to add.*/
1132
void addEnumerator( EnumeratorDom e );
1133
/**Removes an enumerator from the model.
1134
@param e The enumerator model to remove.*/
1135
void removeEnumerator( EnumeratorDom e );
1137
virtual void read( QDataStream& stream );
1138
virtual void write( QDataStream& stream ) const;
1142
QMap<QString, EnumeratorDom> m_enumerators;
1145
EnumModel( const EnumModel& source );
1146
void operator = ( const EnumModel& source );
1147
friend class CodeModel;
1153
Represents enumerators. Enums consist of enumerators, for example in code:
1155
enum Type { A, B, C};
1157
Type is represented as EnumModel;\n
1158
A, B, C are represented with EnumeratorModel.
1160
Instanses of this class should be created using @ref CodeModel::create method.
1162
class EnumeratorModel: public CodeModelItem
1166
@param model Code model which stores this item.*/
1167
EnumeratorModel( CodeModel* model );
1170
/**A definition of safe pointer to the enumerator model.*/
1171
typedef EnumeratorDom Ptr;
1173
virtual bool isEnumerator() const { return true; }
1175
/**@return The value of an enumerator.*/
1176
QString value() const;
1177
/**Sets the value of an enumerator.
1178
@param value The value.*/
1179
void setValue( const QString& value );
1181
virtual void read( QDataStream& stream );
1182
virtual void write( QDataStream& stream ) const;
1188
EnumeratorModel( const EnumeratorModel& source );
1189
void operator = ( const EnumeratorModel& source );
1190
friend class CodeModel;
1196
Represents type aliases (like aliases in Ada and typedefs in c++).
1198
class TypeAliasModel: public CodeModelItem
1202
@param model Code model which stores this item.*/
1203
TypeAliasModel( CodeModel* model );
1206
/**A definition of safe pointer to the type alias model.*/
1207
typedef TypeAliasDom Ptr;
1209
virtual bool isTypeAlias() const { return true; }
1211
/**@return The actual type of an alias.*/
1212
QString type() const;
1213
/**Sets the type of an alias.
1214
@param type The type name.*/
1215
void setType( const QString& type );
1217
virtual void read( QDataStream& stream );
1218
virtual void write( QDataStream& stream ) const;
1224
TypeAliasModel( const TypeAliasModel& source );
1225
void operator = ( const TypeAliasModel& source );
1226
friend class CodeModel;