~ubuntu-branches/debian/sid/kdevelop/sid

« back to all changes in this revision

Viewing changes to lib/interfaces/codemodel.h

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Lainé
  • Date: 2010-05-05 07:21:55 UTC
  • mfrom: (1.2.3 upstream) (5.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100505072155-h78lx19pu04sbhtn
Tags: 4:4.0.0-2
* Upload to unstable (Closes: #579947, #481832).
* Acknowledge obsolete NMU fixes (Closes: #562410, #546961).

Show diffs side-by-side

added added

removed removed

Lines of Context:
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>
5
 
 
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.
10
 
 
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.
15
 
 
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.
20
 
*/
21
 
#ifndef CODEMODEL_H
22
 
#define CODEMODEL_H
23
 
 
24
 
/**
25
 
@file codemodel.h
26
 
Code Model - a memory symbol store.
27
 
*/
28
 
 
29
 
 
30
 
#include <qmap.h>
31
 
#include <qstringlist.h>
32
 
#include <ksharedptr.h>
33
 
#include <qvaluevector.h>
34
 
#include "hashedstring.h"
35
 
 
36
 
#include <iostream>
37
 
#include <ostream>
38
 
#include <string>
39
 
#include <sstream>
40
 
#include <set>
41
 
 
42
 
enum ParsedFileType {
43
 
  CppParsedFile
44
 
};
45
 
 
46
 
class AbstractParseResult : public KShared {
47
 
public:
48
 
  virtual void read( QDataStream& stream ) = 0;
49
 
 
50
 
  virtual void write( QDataStream& stream ) const = 0;
51
 
 
52
 
  virtual ParsedFileType type() const = 0;
53
 
};
54
 
 
55
 
typedef KSharedPtr<AbstractParseResult> ParseResultPointer;
56
 
  
57
 
using namespace std;
58
 
 
59
 
class CodeModel;
60
 
class CodeModelItem;
61
 
class FileModel;
62
 
class NamespaceModel;
63
 
class ClassModel;
64
 
class FunctionModel;
65
 
class FunctionDefinitionModel;
66
 
class VariableModel;
67
 
class ArgumentModel;
68
 
class EnumModel;
69
 
class EnumeratorModel;
70
 
class TypeAliasModel;
71
 
 
72
 
/**
73
 
@class ItemDom
74
 
Safe pointer to the @ref CodeModelItem.
75
 
This is a type definition: @code typedef KSharedPtr<CodeModelItem> ItemDom; @endcode
76
 
@sa KSharedPtr
77
 
*/
78
 
typedef KSharedPtr<CodeModelItem> ItemDom;
79
 
 
80
 
/**
81
 
@class FileDom
82
 
Safe pointer to the @ref FileModel.
83
 
This is a type definition: @code typedef KSharedPtr<FileModel> FileDom; @endcode
84
 
@sa KSharedPtr
85
 
*/
86
 
typedef KSharedPtr<FileModel> FileDom;
87
 
 
88
 
/**
89
 
@class NamespaceDom
90
 
Safe pointer to the @ref NamespaceModel.
91
 
This is a type definition: @code typedef KSharedPtr<NamespaceModel> NamespaceDom; @endcode
92
 
@sa KSharedPtr
93
 
*/
94
 
typedef KSharedPtr<NamespaceModel> NamespaceDom;
95
 
 
96
 
/**
97
 
@class ClassDom
98
 
Safe pointer to the @ref ClassModel.
99
 
This is a type definition: @code typedef KSharedPtr<ClassModel> ClassDom; @endcode
100
 
@sa KSharedPtr
101
 
*/
102
 
typedef KSharedPtr<ClassModel> ClassDom;
103
 
 
104
 
/**
105
 
@class FunctionDom
106
 
Safe pointer to the @ref FunctionModel.
107
 
This is a type definition: @code typedef KSharedPtr<FunctionModel> FunctionDom; @endcode
108
 
@sa KSharedPtr
109
 
*/
110
 
typedef KSharedPtr<FunctionModel> FunctionDom;
111
 
 
112
 
/**
113
 
@class FunctionDefinitionDom
114
 
Safe pointer to the @ref FunctionDefinitionModel.
115
 
This is a type definition: @code typedef KSharedPtr<FunctionDefinitionModel> FunctionDefinitionDom; @endcode
116
 
@sa KSharedPtr
117
 
*/
118
 
typedef KSharedPtr<FunctionDefinitionModel> FunctionDefinitionDom;
119
 
 
120
 
/**
121
 
@class VariableDom
122
 
Safe pointer to the @ref VariableModel.
123
 
This is a type definition: @code typedef KSharedPtr<VariableModel> VariableDom; @endcode
124
 
@sa KSharedPtr
125
 
*/
126
 
typedef KSharedPtr<VariableModel> VariableDom;
127
 
 
128
 
/**
129
 
@class ArgumentDom
130
 
Safe pointer to the @ref ArgumentModel.
131
 
This is a type definition: @code typedef KSharedPtr<ArgumentModel> ArgumentDom; @endcode
132
 
@sa KSharedPtr
133
 
*/
134
 
typedef KSharedPtr<ArgumentModel> ArgumentDom;
135
 
 
136
 
/**
137
 
@class EnumDom
138
 
Safe pointer to the @ref EnumModel.
139
 
This is a type definition: @code typedef KSharedPtr<EnumModel> EnumDom; @endcode
140
 
@sa KSharedPtr
141
 
*/
142
 
typedef KSharedPtr<EnumModel> EnumDom;
143
 
 
144
 
/**
145
 
@class TypeAliasDom
146
 
Safe pointer to the @ref TypeAliasModel.
147
 
This is a type definition: @code typedef KSharedPtr<TypeAliasModel> TypeAliasDom; @endcode
148
 
@sa KSharedPtr
149
 
*/
150
 
typedef KSharedPtr<TypeAliasModel> TypeAliasDom;
151
 
 
152
 
/**
153
 
@class EnumeratorDom
154
 
Safe pointer to the @ref EnumeratorModel.
155
 
This is a type definition: @code typedef KSharedPtr<EnumeratorModel> EnumeratorDom; @endcode
156
 
@sa KSharedPtr
157
 
*/
158
 
typedef KSharedPtr<EnumeratorModel> EnumeratorDom;
159
 
 
160
 
/**
161
 
@class ItemList
162
 
The list of code model items.
163
 
This is a type definition: @code typedef QValueList<ItemDom> ItemList; @endcode
164
 
@sa QValueList
165
 
*/
166
 
typedef QValueList<ItemDom> ItemList;
167
 
 
168
 
/**
169
 
@class FileList
170
 
The list of code model files.
171
 
This is a type definition: @code typedef QValueList<FileDom> FileList; @endcode
172
 
@sa QValueList
173
 
*/
174
 
typedef QValueList<FileDom> FileList;
175
 
 
176
 
/**
177
 
@class NamespaceList
178
 
The list of code model namespaces.
179
 
This is a type definition: @code typedef QValueList<NamespaceDom> NamespaceList; @endcode
180
 
@sa QValueList
181
 
*/
182
 
typedef QValueList<NamespaceDom> NamespaceList;
183
 
 
184
 
/**
185
 
@class ClassList
186
 
The list of code model classes.
187
 
This is a type definition: @code typedef QValueList<ClassDom> ClassList; @endcode
188
 
@sa QValueList
189
 
*/
190
 
typedef QValueList<ClassDom> ClassList;
191
 
 
192
 
/**
193
 
@class FunctionList
194
 
The list of code model functions.
195
 
This is a type definition: @code typedef QValueList<FunctionDom> FunctionList; @endcode
196
 
@sa QValueList
197
 
*/
198
 
typedef QValueList<FunctionDom> FunctionList;
199
 
 
200
 
/**
201
 
@class FunctionDefinitionList
202
 
The list of code model function definitions.
203
 
This is a type definition: @code typedef QValueList<FunctionDefinitionDom> FunctionDefinitionList; @endcode
204
 
@sa QValueList
205
 
*/
206
 
 
207
 
typedef QValueList<FunctionDefinitionDom> FunctionDefinitionList;
208
 
/**
209
 
@class VariableList
210
 
The list of code model variables.
211
 
This is a type definition: @code typedef QValueList<VariableDom> VariableList; @endcode
212
 
@sa QValueList
213
 
*/
214
 
typedef QValueList<VariableDom> VariableList;
215
 
 
216
 
/**
217
 
@class ArgumentList
218
 
The list of code model arguments.
219
 
This is a type definition: @code typedef QValueList<ArgumentDom> ArgumentList; @endcode
220
 
@sa QValueList
221
 
*/
222
 
typedef QValueList<ArgumentDom> ArgumentList;
223
 
 
224
 
/**
225
 
@class EnumList
226
 
The list of code model enums.
227
 
This is a type definition: @code typedef QValueList<EnumDom> EnumList; @endcode
228
 
@sa QValueList
229
 
*/
230
 
typedef QValueList<EnumDom> EnumList;
231
 
 
232
 
/**
233
 
@class TypeAliasList
234
 
The list of code model type aliases.
235
 
This is a type definition: @code typedef QValueList<TypeAliasDom> TypeAliasList; @endcode
236
 
@sa QValueList
237
 
*/
238
 
typedef QValueList<TypeAliasDom> TypeAliasList;
239
 
 
240
 
/**
241
 
@class EnumeratorList
242
 
The list of code model enumerators.
243
 
This is a type definition: @code typedef QValueList<EnumeratorDom> EnumeratorList; @endcode
244
 
@sa QValueList
245
 
*/
246
 
typedef QValueList<EnumeratorDom> EnumeratorList;
247
 
 
248
 
/**
249
 
Iterates through @p lst and creates sorted list of code model item names.
250
 
Can be used, for example, to get the list of classes in the store:
251
 
@code
252
 
QStringList classList = sortedNameList(codeModel()->globalNamespace()->classList());
253
 
@endcode
254
 
@param lst The list to iterate.
255
 
@return Sorted list of code model item names.
256
 
*/
257
 
template <class ItemList>
258
 
QStringList sortedNameList( const ItemList& lst )
259
 
{
260
 
    QStringList nameList;
261
 
 
262
 
    typename ItemList::ConstIterator it = lst.begin();
263
 
    while( it != lst.end() ){
264
 
        if( !(*it)->name().isEmpty() )
265
 
            nameList << (*it)->name();
266
 
        ++it;
267
 
    }
268
 
 
269
 
    nameList.sort();
270
 
    return nameList;
271
 
}
272
 
 
273
 
/**
274
 
Casts safe code model pointers (@p KSharedPtr<T> objects like
275
 
FileDom, NamespaceDom, etc.) to the @p Result type.
276
 
 
277
 
Example:
278
 
@code
279
 
//ns is of type NamespaceDom
280
 
ClassDom cl = model_cast<ClassDom>(ns);
281
 
@endcode
282
 
@param x Object to cast.
283
 
*/
284
 
template <class Result, class T>
285
 
Result model_cast( KSharedPtr<T> x )
286
 
{
287
 
    Result r( static_cast<T*>(x) );
288
 
    return r;
289
 
}
290
 
 
291
 
/**
292
 
Casts code model pointers (objects like
293
 
FileModel, NamespaceModel, etc.) to the @p Result type.
294
 
 
295
 
Example:
296
 
@code
297
 
//ns is of type NamespaceModel*
298
 
ClassDom cl = model_cast<ClassDom>(ns);
299
 
@endcode
300
 
@param x Object to cast.
301
 
*/
302
 
template <class Result, class T>
303
 
Result model_cast( T* x )
304
 
{
305
 
    Result r( static_cast<T*>(x) );
306
 
    return r;
307
 
}
308
 
 
309
 
 
310
 
/**
311
 
Code Model - a memory symbol store.
312
 
Symbol store (aka class store) is a database of symbols
313
 
found in code with the important information about those symbols.
314
 
 
315
 
For example, programming language support plugins use symbol store
316
 
to remember information about classes, functions, etc. For each type
317
 
of symbol a certain information can be stored - symbol name, the
318
 
location in source file, etc.
319
 
 
320
 
@sa codemodel.h documentation for a list of typedefs and other convenience functions.
321
 
 
322
 
@sa codemodel_utils.h documentation for an additional code model utility functions and classes reference.
323
 
*/
324
 
class CodeModel
325
 
{
326
 
public:
327
 
    /**Constructor.*/
328
 
    CodeModel();
329
 
    /**Destructor.*/
330
 
    virtual ~CodeModel();
331
 
 
332
 
    /**Creates a code model item. This should be used to create
333
 
    code model items.
334
 
    
335
 
    For example, to create a class model somewhere in your plugin, use:
336
 
    @code
337
 
    klass = codeModel()->create<ClassModel>();
338
 
    klass->setName("ClassName");
339
 
    klass->setFileName("FileName");
340
 
    klass->setStartPosition(line, column);
341
 
    @endcode
342
 
    @return Created code model item.*/
343
 
    template <class T> typename T::Ptr create()
344
 
    {
345
 
        typename T::Ptr ptr( new T(this) );
346
 
        return ptr;
347
 
    }
348
 
 
349
 
    /**Resets the CodeModel.*/
350
 
    void wipeout();
351
 
 
352
 
    /**Gets the list of files in the store.
353
 
    @return The FileList object that contains the list of files.*/
354
 
    FileList fileList();
355
 
 
356
 
    /**Gets the list of files in the store.
357
 
    This is a const version for convenience.
358
 
    @return The FileList object that contains the list of files.*/
359
 
    const FileList fileList() const;
360
 
 
361
 
    /**Checks to see if a file is in the store.
362
 
    @return true if @p name is in the file list.*/
363
 
    bool hasFile( const QString& name ) const;
364
 
 
365
 
    /**Gets the FileDom object for a file.
366
 
    @param name The name of the file to get the FileDom object for.*/
367
 
    FileDom fileByName( const QString& name );
368
 
 
369
 
    /**Gets the FileDom object for a file.
370
 
    This is a const version provided for convenience.
371
 
    @param name the name of the file to get the FileDom object for.*/
372
 
    const FileDom fileByName( const QString& name ) const;
373
 
 
374
 
    /**Adds a file to the store.
375
 
    @param file The FileDom object to add to the store.
376
 
    @return true if the file was added successfully.*/
377
 
    bool addFile( FileDom file );
378
 
 
379
 
    /**Removes a file from the store.
380
 
    @param file the FileDom object to remove from the store.*/
381
 
    void removeFile( FileDom file  );
382
 
 
383
 
    /**Gets the global namespace
384
 
    @return The NamespaceDom object that represents the global namespace.*/
385
 
    const NamespaceDom globalNamespace() const;
386
 
 
387
 
    /**Reads the model from a stream.
388
 
    Use this to save the memory symbol store to a file.
389
 
    
390
 
    Language support plugins usually save symbols from projects before the project is 
391
 
    closed to avoid reparsing when the project is opened next time.
392
 
    @param stream Stream to read from.
393
 
    @return whether the read succeeded(may fail when the store-format is deprecated).*/
394
 
    virtual void read( QDataStream& stream );
395
 
    /**Writes the model to a stream.
396
 
    Use this to restore the memory symbol store to a file.
397
 
    
398
 
    Language support plugins usually save symbols from projects before the project is 
399
 
    closed to avoid reparsing when the project is opened next time.
400
 
    @param stream Stream to write to.*/
401
 
    virtual void write( QDataStream& stream ) const;
402
 
    
403
 
    /** this will dump the whole tree into dot-file-format so it can be inspected, not ready yet*/
404
 
    virtual void dump( std::ostream& file, QString Info="" );
405
 
    
406
 
    /** Merges two groups, by changing the group-ids of the files.
407
 
    Returns the id of the new group, or 0 on fail.
408
 
    @param g1 first group
409
 
    @param g2 second group */
410
 
    int mergeGroups( int g1, int g2 );
411
 
    
412
 
    /** Returns all files within the given group 
413
 
    it should be preferred calling FileModel::wholeGroup and 
414
 
    FileModel::wholeGroupStrings because those return in constant
415
 
    time if they are the only member of the group */
416
 
    FileList getGroup( int gid ) const;
417
 
    
418
 
    FileList getGroup( const FileDom& file) const;
419
 
    
420
 
    /** Same as above, but returns the names instead of the objects */
421
 
    virtual QStringList getGroupStrings( int gid ) const;
422
 
    
423
 
private:
424
 
    /**Adds a namespace to the store.
425
 
    @param target The NamespaceDom object that the namespace will be added to.
426
 
    @param source The NamespaceDom object that contains the namespace to remove.*/
427
 
    void addNamespace( NamespaceDom target, NamespaceDom source );
428
 
 
429
 
    /**Removes a namespace from the store.
430
 
    @param target The NamespaceDom object that the namespace will be removed from.
431
 
    @param source The NamespaceDom object that contains the namespace to remove.*/
432
 
    void removeNamespace( NamespaceDom target, NamespaceDom source );
433
 
 
434
 
private:
435
 
    QMap<QString, FileDom> m_files;
436
 
    NamespaceDom m_globalNamespace;
437
 
 
438
 
    virtual int newGroupId();
439
 
    ///the groups were introduced to represent dependencies between different files.
440
 
    ///Files can have slaves that are owned by other files within the same group.
441
 
    ///While parsing, whole groups should always be parsed/reparsed together.
442
 
    int m_currentGroupId;   ///normally, each file has its own group.
443
 
    
444
 
private:
445
 
    CodeModel( const CodeModel& source );
446
 
    void operator = ( const CodeModel& source );
447
 
    friend class CodeModelItem;
448
 
    friend class FileModel;
449
 
};
450
 
 
451
 
 
452
 
/**
453
 
Item in code model (symbol store).
454
 
Item is a symbol in a store. Code model provides several predefined classes
455
 
for predefined item types (files, namespaces, classes, functions and function definitions,
456
 
variables, arguments, enums and enumerators, type aliases.
457
 
 
458
 
Instances of this class should be created using @ref CodeModel::create method but usually
459
 
it is better to create instances of derived classes like ClassModel, NamespaceModel, FileModel, etc.
460
 
*/
461
 
class CodeModelItem: public KShared
462
 
{
463
 
public:
464
 
    /**A definition of safe pointer to the code model item.*/
465
 
    typedef ItemDom Ptr;
466
 
 
467
 
    /**A type of a code model item.*/
468
 
    enum Kind
469
 
    {
470
 
        File,                /**<File.*/
471
 
        Namespace,           /**<Namespace.*/
472
 
        Class,               /**<Class.*/
473
 
        Function,            /**<Function or class method.*/
474
 
        Variable,            /**<Variable.*/
475
 
        Argument,            /**<Function or method parameter.*/
476
 
        FunctionDefinition,  /**<Function definition.*/
477
 
        Enum,                /**<Enum.*/
478
 
        Enumerator,          /**<Enumerator - a member of an Enum (example: @code enum Type { A, B, C} @endcode 
479
 
                                Type will be an Enum; A, B and C - Enumerators.*/
480
 
        TypeAlias,           /**<Type alias (aka typedef in c++).*/
481
 
    
482
 
        Custom = 1000        /**<Custom model items should have type greater than 1000*/
483
 
    };
484
 
 
485
 
    /**An access to the code model item.*/
486
 
    enum Access
487
 
    {
488
 
        Public,        /**<Public.*/
489
 
        Protected,     /**<Protected.*/
490
 
        Private        /**<Private.*/
491
 
    };
492
 
    void update( const CodeModelItem* i );
493
 
    bool canUpdate( const CodeModelItem* i ) const;
494
 
 
495
 
protected:
496
 
    /**Constructor.
497
 
    @param kind The type, see also @ref CodeModelItem::Kind.
498
 
    @param model Code model which stores this item.*/
499
 
    CodeModelItem( int kind, CodeModel* model );
500
 
 
501
 
public:
502
 
    /**Destructor.*/
503
 
    virtual ~CodeModelItem();
504
 
 
505
 
    /**@return The type (kind) of item.*/
506
 
    int kind() const { return m_kind; }
507
 
 
508
 
    /**Sets the type (kind) of item.
509
 
    @param kind The type, see also @ref CodeModelItem::Kind.*/
510
 
    void setKind( int kind ) { m_kind = kind; }
511
 
 
512
 
    /**@return The name of the item.*/
513
 
    QString name() const;
514
 
 
515
 
    QString comment() const {
516
 
        return m_comment;
517
 
    }
518
 
    
519
 
    void setComment( QString comment ) {
520
 
        m_comment = comment;
521
 
    }
522
 
    
523
 
    /**Sets the name of the item.
524
 
    @param name The name.*/
525
 
    void setName( const QString& name );
526
 
 
527
 
    /**Gets the file of the item.
528
 
    @return The FileDom object for the item.*/
529
 
    FileDom file();
530
 
 
531
 
    /**Gets the file of the item
532
 
    This is a const version provided for convenience.
533
 
    @return The FileDom object for the item.*/
534
 
    const FileDom file() const;
535
 
 
536
 
    /**@return The filename of the item.*/
537
 
    QString fileName() const;
538
 
 
539
 
    /**Sets the filename of the item.
540
 
    @param fileName The file name.*/
541
 
    void setFileName( const QString& fileName );
542
 
 
543
 
    /**Gets the start position of the item.
544
 
    @param line Will be set to the line number of the items start position. Pass 0 if line number is not necessary.
545
 
    @param col Will be set to the column number of the items start position. Pass 0 if column number is not necessary.*/
546
 
    void getStartPosition( int* line, int* col ) const;
547
 
 
548
 
    /**Sets the start position of the item.
549
 
    @param line Line number.
550
 
    @param col Column number.*/
551
 
    void setStartPosition( int line, int col );
552
 
 
553
 
    /**Get the end position of the item.
554
 
    @param line Will be set to the line number of the items end position. Pass 0 if line number is not necessary.
555
 
    @param col Will be set to the column number of the items end position. Pass 0 if column number is not necessary.*/
556
 
    void getEndPosition( int* line, int* col ) const;
557
 
 
558
 
    /**Set the end position of the item.
559
 
    @param line Line number.
560
 
    @param col Column number.*/
561
 
    void setEndPosition( int line, int col );
562
 
 
563
 
    /**@return true if an item is a FileModel.*/
564
 
    virtual bool isFile() const { return false; }
565
 
    /**@return true if an item is a NamespaceModel.*/
566
 
    virtual bool isNamespace() const { return false; }
567
 
    /**@return true if an item is a ClassModel.*/
568
 
    virtual bool isClass() const { return false; }
569
 
    /**@return true if an item is a FunctionModel.*/
570
 
    virtual bool isFunction() const { return false; }
571
 
    /**@return true if an item is a FileDefinitionModel.*/
572
 
    virtual bool isFunctionDefinition() const { return false; }
573
 
    /**@return true if an item is a VariableModel.*/
574
 
    virtual bool isVariable() const { return false; }
575
 
    /**@return true if an item is an ArgumentModel.*/
576
 
    virtual bool isArgument() const { return false; }
577
 
    /**@return true if an item is a EnumModel.*/
578
 
    virtual bool isEnum() const { return false; }
579
 
    /**@return true if an item is a EnumeratorModel.*/
580
 
    virtual bool isEnumerator() const { return false; }
581
 
    /**@return true if an item is a TypeAliasModel.*/
582
 
    virtual bool isTypeAlias() const { return false; }
583
 
    /**@return true if an item is a custom item.*/
584
 
    virtual bool isCustom() const { return false; }
585
 
    
586
 
    virtual bool isTemplateable() const { return false; }
587
 
 
588
 
    /**Reads an item from the stream.
589
 
    @param stream The stream to read from.*/
590
 
    virtual void read( QDataStream& stream );
591
 
    /**Writes an item to the stream.
592
 
    @param stream The stream to write to.*/
593
 
    virtual void write( QDataStream& stream ) const;
594
 
 
595
 
    virtual void dump( std::ostream& file, bool recurse=false, QString Info="" );
596
 
    
597
 
    /**@return The code model for this item.*/
598
 
    CodeModel* codeModel() { return m_model; }
599
 
 
600
 
    /**@note This is a const version provided for convenience.
601
 
    @return The code model for this item*/
602
 
    const CodeModel* codeModel() const { return m_model; }
603
 
 
604
 
private:
605
 
    int m_kind;
606
 
    CodeModel* m_model;
607
 
    QString m_name;
608
 
    QString m_fileName;
609
 
    QString m_comment; ///not stored yet
610
 
    int m_startLine, m_startColumn;
611
 
    int m_endLine, m_endColumn;
612
 
 
613
 
private:
614
 
    CodeModelItem( const CodeModelItem& source );
615
 
    void operator = ( const CodeModelItem& source );
616
 
};
617
 
 
618
 
 
619
 
 
620
 
class TemplateModelItem {
621
 
    public:
622
 
        typedef QPair< QString, QString > ParamPair;
623
 
        typedef QValueVector< ParamPair > ParamMap; ///The first is the name, and the second the default-parameter, or "" if there is none.
624
 
        
625
 
        virtual const ParamMap& getTemplateParams() {
626
 
            return m_params;
627
 
        }
628
 
        
629
 
        virtual void addTemplateParam( QString name, QString def = "" ) {
630
 
            m_params.push_back( ParamPair( name, def ) );
631
 
        }
632
 
        
633
 
        virtual void clearTemplateParams() {
634
 
            m_params.clear();
635
 
        }
636
 
 
637
 
                                bool hasSpecializationDeclaration() const {
638
 
                                        return !m_specialization.isEmpty();
639
 
                                }
640
 
 
641
 
                                virtual QString getSpecializationDeclaration() const {
642
 
                                        return m_specialization;
643
 
                                }
644
 
 
645
 
                                void setSpecializationDeclaration( const QString& str ) {
646
 
                                        m_specialization = str;
647
 
                                }
648
 
        
649
 
        ///returns -1 if the parameter does not exist
650
 
        virtual int findTemplateParam( const QString& name ) const {
651
 
            for( unsigned int a = 0; a< m_params.size(); a++) 
652
 
                if( m_params[a].first == name ) return a;
653
 
            return -1;
654
 
       }
655
 
        
656
 
       const ParamPair getParam( int index ) const {
657
 
           return m_params[index];
658
 
       }
659
 
       
660
 
       virtual bool isTemplateable() const  { return true; }
661
 
    
662
 
       void write(  QDataStream & stream ) const {
663
 
                                         stream << m_specialization;
664
 
           stream << (int)m_params.size();
665
 
           for( ParamMap::const_iterator it = m_params.begin(); it != m_params.end(); ++it ) {
666
 
               stream << (*it).first;
667
 
               stream << (*it).second;
668
 
           }
669
 
       }
670
 
       
671
 
       void read(  QDataStream & stream )  {
672
 
           int count;
673
 
                                         stream >> m_specialization;
674
 
           stream >> count;
675
 
           for( int a = 0; a < count; a++ ) {
676
 
               ParamPair tmp;
677
 
               stream >> tmp.first;
678
 
               stream >> tmp.second;
679
 
               m_params.push_back( tmp );
680
 
           }
681
 
       }
682
 
    
683
 
    protected:
684
 
        ParamMap m_params;
685
 
                                QString m_specialization;
686
 
};
687
 
 
688
 
 
689
 
 
690
 
/**
691
 
Class model.
692
 
Represents a class in the code model.
693
 
 
694
 
Instances of this class should be created using @ref CodeModel::create method.
695
 
*/
696
 
class ClassModel: public CodeModelItem, public TemplateModelItem
697
 
{
698
 
protected:
699
 
    /**Constructor.
700
 
    @param model Code model which stores this item.*/
701
 
    ClassModel( CodeModel* model );
702
 
 
703
 
public:
704
 
    /**A definition of safe pointer to the class model.*/
705
 
    typedef ClassDom Ptr;
706
 
 
707
 
    virtual bool isClass() const { return true; }
708
 
 
709
 
    /**@return The scope of the class. Scope is a string list composed from names of parent classes and namespaces.*/
710
 
    QStringList scope() const { return m_scope; }
711
 
    /**Sets the scope of this class.
712
 
    @param scope The scope - a list of parent classes and namespaces.*/
713
 
    void setScope( const QStringList& scope ) { m_scope = scope; }
714
 
 
715
 
    /**@return The list of base class names.*/
716
 
    QStringList baseClassList() const;
717
 
 
718
 
    /**Adds a base class to the list of base classes.
719
 
    @param baseClass The base class name.*/
720
 
    bool addBaseClass( const QString& baseClass );
721
 
 
722
 
    /**Removes a base class from the list of base classes.
723
 
    @param baseClass The base class name.*/
724
 
    void removeBaseClass( const QString& baseClass );
725
 
 
726
 
    /**@return The list of (sub)classes in this model.*/
727
 
    ClassList classList();
728
 
 
729
 
    /**@note This is a const version provided for convenience.
730
 
    @return The list of (sub)classes in this model.*/
731
 
    const ClassList classList() const;
732
 
 
733
 
    /**Checks if the class specified by @p name is in this model.
734
 
    @param name The name of a class to look for.
735
 
    @return true if the model has a class.*/
736
 
    bool hasClass( const QString& name ) const;
737
 
 
738
 
    /**@param name The name of a class.
739
 
    @return A list of classes that match the name given by @p name.*/
740
 
    ClassList classByName( const QString& name );
741
 
 
742
 
    /**@param name The name of a class.
743
 
    @return A list of classes that match the name given by @p name.
744
 
    @note This is a const version provided for convenience.*/
745
 
    const ClassList classByName( const QString& name ) const;
746
 
 
747
 
    /**Adds a class to the model.
748
 
    @param klass The class model to add.
749
 
    @return true if addition was successful.*/
750
 
    bool addClass( ClassDom klass );
751
 
 
752
 
    /**Removes a class from the model.
753
 
    @param klass The class model to remove.*/    
754
 
    void removeClass( ClassDom klass );
755
 
 
756
 
    /**@return A list of functions in the model.*/
757
 
    FunctionList functionList();
758
 
 
759
 
    /**@return A list of functions in the model.
760
 
    @note This is a const version provided for convenience.*/
761
 
    const FunctionList functionList() const;
762
 
 
763
 
    /**Check if the function specified by @p name is in the model.
764
 
    @param name The name of a function to look for.
765
 
    @return true if the model has a class.*/
766
 
    bool hasFunction( const QString& name ) const;
767
 
 
768
 
    /**@param name The name of a function to look for.
769
 
    @return A list of functions that match the name given by @p name.*/
770
 
    FunctionList functionByName( const QString& name );
771
 
 
772
 
    /**@param name The name of a function to look for.
773
 
    @return A list of functions that match the name given by @p name.
774
 
    @note This is a const version provided for convenience.*/
775
 
    const FunctionList functionByName( const QString& name ) const;
776
 
 
777
 
    /**Adds a function to the class model.
778
 
    @param fun The function model to add.
779
 
    @return true if addition was successful.*/
780
 
    bool addFunction( FunctionDom fun );
781
 
 
782
 
    /**Removes a function from the class model.
783
 
    @param fun The FunctionDom object to remove from the model.*/
784
 
    void removeFunction( FunctionDom fun );
785
 
 
786
 
    /**@return The list of function definitions in the model.*/
787
 
    FunctionDefinitionList functionDefinitionList();
788
 
 
789
 
    /**@return The list of function definitions
790
 
    @note This is a const version provided for convenience.*/
791
 
    const FunctionDefinitionList functionDefinitionList() const;
792
 
 
793
 
    /**Checks if the function definition specified by \p name is in the model.
794
 
    @param name The name of a function definition to look for.
795
 
    @return true if the function definition was found.*/
796
 
    bool hasFunctionDefinition( const QString& name ) const;
797
 
 
798
 
    /**Gets the list of functions that match the name given by \p name.
799
 
    If there are no matches, then the list returned is empty.
800
 
    @param name The name of a function definition to look for.
801
 
    @return The FunctionDefinitionList object containing the definitions that match.*/
802
 
    FunctionDefinitionList functionDefinitionByName( const QString& name );
803
 
 
804
 
    /**Gets the list of functions that match the name given by \p name.
805
 
    If there are no matches, then the list returned is empty.
806
 
    @param name The name of a function definition to look for.
807
 
    @return The FunctionDefinitionList object containing the definitions that match.
808
 
    @note This is a const version provided for convenience.*/
809
 
    const FunctionDefinitionList functionDefinitionByName( const QString& name ) const;
810
 
 
811
 
    /**Adds a function definition to the model.
812
 
    @param fun The function fefinition model to add to the model.
813
 
    @return true if the addition was successful.*/
814
 
    bool addFunctionDefinition( FunctionDefinitionDom fun );
815
 
 
816
 
    /**Removes a function definition from the model.
817
 
    @param fun The function fefinition model to remove from the model.*/
818
 
    void removeFunctionDefinition( FunctionDefinitionDom fun );
819
 
 
820
 
    /**@return The list of variables in the model.*/
821
 
    VariableList variableList();
822
 
 
823
 
    /**@return The list of variables in the model.
824
 
    @note This is a const version provided for convenience.*/
825
 
    const VariableList variableList() const;
826
 
 
827
 
    /**Checks if the variable specified by @p name is in the model.
828
 
    @param name The name of a variable.
829
 
    @return true if the variable was found.*/
830
 
    bool hasVariable( const QString& name ) const;
831
 
 
832
 
    /**Gets the variable specified by @p name.
833
 
    If there are no matches, then the VariableDom object returned is empty.
834
 
    @param name The name of a variable.
835
 
    @return A VariableDom object that matches the name specified.*/
836
 
    VariableDom variableByName( const QString& name );
837
 
 
838
 
    /**Gets the variable specified by @p name.
839
 
    If there are no matches, then the VariableDom object returned is empty.
840
 
    @param name The name of a variable.
841
 
    @return A VariableDom object that matches the name specified.
842
 
    @note This is a const version provided for convenience.*/
843
 
    const VariableDom variableByName( const QString& name ) const;
844
 
 
845
 
    /**Adds a variable to the model.
846
 
    @param var The variable model to add to the model.
847
 
    @return true if the addition was successful.*/
848
 
    bool addVariable( VariableDom var );
849
 
 
850
 
    /**Removes a variable from the model.
851
 
    @param var The variable model to remove from the model.*/
852
 
    void removeVariable( VariableDom var );
853
 
 
854
 
    /**@return The type alias list for this model.*/
855
 
    TypeAliasList typeAliasList();
856
 
 
857
 
    /**@return The type alias list for this model.
858
 
    @note This is a const version provided for convenience.*/
859
 
    const TypeAliasList typeAliasList() const;
860
 
 
861
 
    /**Checks if the type alias specified by @p name is in the model.
862
 
    @param name The name of a type alias.
863
 
    @return true if the type alias was found.*/
864
 
    bool hasTypeAlias( const QString& name ) const;
865
 
 
866
 
    /**Gets the list of type aliases that match @p name.
867
 
    If there are no matches, the TypeAliasList object is empty.
868
 
    @param name The name of a type alias.
869
 
    @return A TypeAliasList object that contains the matches.*/
870
 
    TypeAliasList typeAliasByName( const QString& name );
871
 
 
872
 
    /**Gets the list of type aliases that match @p name.
873
 
    If there are no matches, the TypeAliasList object is empty.
874
 
    @param name The name of a type alias.
875
 
    @return A TypeAliasList object that contains the matches.
876
 
    @note This is a const version provided for convenience.*/
877
 
    const TypeAliasList typeAliasByName( const QString& name ) const;
878
 
 
879
 
    /**Adds a type alias to the model.
880
 
    @param typeAlias The type alias model to add to the model.
881
 
    @return true if the addition was successful.*/
882
 
    bool addTypeAlias( TypeAliasDom typeAlias );
883
 
 
884
 
    /**Removes a type alias from the model.
885
 
    @param typeAlias The TypeAliasDom object to remove from the model.*/
886
 
    void removeTypeAlias( TypeAliasDom typeAlias );
887
 
 
888
 
    /**@return The list of enums in the model.*/
889
 
    EnumList enumList();
890
 
 
891
 
    /**@return The list of enums in the model.
892
 
    @note This is a const version provided for convenience.*/
893
 
    const EnumList enumList() const;
894
 
 
895
 
    /**Checks if the enum specified by @p name is in the model.
896
 
    @param name The name of an enum.
897
 
    @return true if the enum was found.*/
898
 
    bool hasEnum( const QString& name ) const;
899
 
 
900
 
    /**Gets the enum specified by @p name.
901
 
    The EnumDom object returned will be empty if no match is found.
902
 
    @param name The name of an enum.
903
 
    @return The EnumDom object that contains the match.*/
904
 
    EnumDom enumByName( const QString& name );
905
 
 
906
 
    /**Gets the enum specified by @p name.
907
 
    The EnumDom object returned will be empty if no match is found.
908
 
    @param name The name of an enum.
909
 
    @return The EnumDom object that contains the match.*/
910
 
    const EnumDom enumByName( const QString& name ) const;
911
 
 
912
 
    /**Adds an enum to the model.
913
 
    @param e The enum model to add to the model.
914
 
    @return true if the addition was successful.*/
915
 
    bool addEnum( EnumDom e );
916
 
 
917
 
    /**Removes an enum from the model.
918
 
    @param e The enum model to remove from the model.*/
919
 
    void removeEnum( EnumDom e );
920
 
 
921
 
    void update( const ClassModel* i );
922
 
    bool canUpdate( const ClassModel* i ) const;
923
 
    
924
 
    virtual void read( QDataStream& stream );
925
 
    virtual void write( QDataStream& stream ) const;
926
 
 
927
 
    virtual void dump( std::ostream& file, bool recurse=false, QString Info="" );
928
 
    
929
 
private:
930
 
    QStringList m_scope;
931
 
    QStringList m_baseClassList;
932
 
    QMap<QString, ClassList> m_classes;
933
 
    QMap<QString, FunctionList> m_functions;
934
 
    QMap<QString, FunctionDefinitionList> m_functionDefinitions;
935
 
    QMap<QString, VariableDom> m_variables;
936
 
    QMap<QString, TypeAliasList> m_typeAliases;
937
 
    QMap<QString, EnumDom> m_enumerators;
938
 
 
939
 
private:
940
 
    ClassModel( const ClassModel& source );
941
 
    void operator = ( const ClassModel& source );
942
 
    friend class CodeModel;
943
 
};
944
 
 
945
 
class NamespaceAliasModel {
946
 
public:
947
 
  virtual void read( QDataStream& stream );
948
 
  virtual void write( QDataStream& stream ) const;
949
 
 
950
 
  QString name() const {
951
 
    return m_name;
952
 
  }
953
 
 
954
 
  void setName( const QString& name ) {
955
 
    m_name = name;
956
 
  }
957
 
 
958
 
  void setAliasName( const QString& theValue ) {
959
 
    m_aliasName = theValue;
960
 
  }
961
 
 
962
 
  QString aliasName() const {
963
 
    return m_aliasName;
964
 
  }
965
 
 
966
 
  void setFileName( const HashedString& theValue ) {
967
 
    m_fileName = theValue;
968
 
  }
969
 
 
970
 
  HashedString fileName() const {
971
 
    return m_fileName;
972
 
  }
973
 
 
974
 
  bool operator < ( const NamespaceAliasModel& rhs ) const {
975
 
    if( m_name < rhs.m_name ) return true;
976
 
    if( m_name == rhs.m_name ) {
977
 
      if( m_aliasName < rhs.m_aliasName ) return true;
978
 
      if(  m_aliasName == rhs.m_aliasName && m_fileName < rhs.m_fileName ) return true;
979
 
    }
980
 
    return false;
981
 
  }
982
 
 
983
 
  bool operator == ( const NamespaceAliasModel& rhs ) const {
984
 
    return m_name == rhs.m_name && m_aliasName == rhs.m_aliasName && m_fileName == rhs.m_fileName;
985
 
  }
986
 
  
987
 
private:
988
 
  QString m_name;
989
 
  QString m_aliasName;
990
 
  HashedString m_fileName;
991
 
};
992
 
 
993
 
class NamespaceImportModel {
994
 
public:
995
 
  virtual void read( QDataStream& stream );
996
 
  virtual void write( QDataStream& stream ) const;
997
 
  
998
 
  QString name() const {
999
 
    return m_name;
1000
 
  }
1001
 
  
1002
 
  HashedString fileName() const {
1003
 
    return m_fileName;
1004
 
  }
1005
 
 
1006
 
  void setName( const QString& name ) {
1007
 
    m_name = name;
1008
 
  }
1009
 
 
1010
 
  void setFileName( const HashedString& file ) {
1011
 
    m_fileName = file;
1012
 
  }
1013
 
  
1014
 
  bool operator < ( const NamespaceImportModel& rhs ) const {
1015
 
    if( m_name < rhs.m_name ) return true;
1016
 
    if( m_name == rhs.m_name )
1017
 
      if( m_fileName < rhs.m_fileName ) return true;
1018
 
 
1019
 
    return false;
1020
 
  }
1021
 
  
1022
 
  bool operator == ( const NamespaceImportModel& rhs ) const {
1023
 
    return m_name == rhs.m_name && m_fileName == rhs.m_fileName;
1024
 
  }
1025
 
  
1026
 
private:
1027
 
  QString m_name;
1028
 
  HashedString m_fileName;
1029
 
};
1030
 
 
1031
 
/**
1032
 
Namespace model.
1033
 
Represents a namespace in the code model.
1034
 
Namespace model can represent either usual c++ namespaces
1035
 
and packages or modules from other languages.
1036
 
 
1037
 
Instances of this class should be created using @ref CodeModel::create method.
1038
 
*/
1039
 
class NamespaceModel: public ClassModel
1040
 
{
1041
 
protected:
1042
 
    /**Constructor.
1043
 
    @param model Code model which stores this item.*/
1044
 
    NamespaceModel( CodeModel* model );
1045
 
 
1046
 
public:
1047
 
  typedef std::set<NamespaceAliasModel> NamespaceAliasModelList; ///I'm using std-sets here, because Qt-3 has no appropriate replacement
1048
 
  typedef std::set<NamespaceImportModel> NamespaceImportModelList;
1049
 
  
1050
 
    /**A definition of safe pointer to the namespace model.*/
1051
 
    typedef NamespaceDom Ptr;
1052
 
 
1053
 
    virtual bool isClass() const { return false; }
1054
 
    virtual bool isNamespace() const { return true; }
1055
 
 
1056
 
    /**@return The list of namespaces in this model.*/
1057
 
    NamespaceList namespaceList();
1058
 
 
1059
 
    /**@return The list of namespaces in this model.
1060
 
    @note This is a const version provided for convenience.*/
1061
 
    const NamespaceList namespaceList() const;
1062
 
 
1063
 
    /**Checks if the namespace referenced by @p name is in the model.
1064
 
    @param name The name of a namespace.
1065
 
    @return true if the namespace was found.*/
1066
 
    bool hasNamespace( const QString& name ) const;
1067
 
 
1068
 
    /**Gets the namespace specified by @p name.
1069
 
    If there are no matches, then the NamespaceDom object returned is empty.
1070
 
    @param name The name of a namespace.
1071
 
    @return The NamespaceDom object that contains the match.*/
1072
 
    NamespaceDom namespaceByName( const QString& name );
1073
 
 
1074
 
    /**Gets the namespace specified by @p name.
1075
 
    If there are no matches, then the NamespaceDom object returned is empty.
1076
 
    @param name The name of a namespace.
1077
 
    @return The NamespaceDom object that contains the match.
1078
 
    @note This is a const version provided for convenience.*/
1079
 
    const NamespaceDom namespaceByName( const QString& name ) const;
1080
 
 
1081
 
    /**Adds a namespace to the model.
1082
 
    @param ns The namespace model to add to the model.
1083
 
    @return true if addition was successful.*/
1084
 
    bool addNamespace( NamespaceDom ns );
1085
 
 
1086
 
    /**Removes the namespace from the model.
1087
 
    @param ns The namespace model to remove from the model.*/
1088
 
    void removeNamespace( NamespaceDom ns );
1089
 
 
1090
 
    /**Updates this model so it has the same content as the other one. Only the line/column is updated. canUpdate(..) must be tested before.
1091
 
     * @param ns the namespace to match
1092
 
    */
1093
 
    void update( const NamespaceModel* ns );
1094
 
    bool canUpdate( const NamespaceModel* ns ) const;
1095
 
    
1096
 
    virtual void read( QDataStream& stream );
1097
 
    virtual void write( QDataStream& stream ) const;
1098
 
 
1099
 
    virtual void dump( std::ostream& file, bool recurse=false, QString Info="" );
1100
 
 
1101
 
    void addNamespaceImport( const NamespaceImportModel& import );
1102
 
    void addNamespaceAlias( const NamespaceAliasModel& alias );
1103
 
    void removeNamespaceImport( const NamespaceImportModel& import );
1104
 
    void removeNamespaceAlias( const NamespaceAliasModel& alias );
1105
 
 
1106
 
    ///Must not be called on temporary objects because a reference is returned(for performance-reasons)
1107
 
    const NamespaceAliasModelList& namespaceAliases() const {
1108
 
      return m_namespaceAliases;
1109
 
    }
1110
 
  
1111
 
    ///Must not be called on temporary objects because a reference is returned(for performance-reasons)
1112
 
    const NamespaceImportModelList& namespaceImports() const {
1113
 
      return m_namespaceImports;
1114
 
    }
1115
 
private:
1116
 
    QMap<QString, NamespaceDom> m_namespaces;
1117
 
    NamespaceAliasModelList m_namespaceAliases;
1118
 
    NamespaceImportModelList m_namespaceImports;
1119
 
 
1120
 
private:
1121
 
  
1122
 
    NamespaceModel( const NamespaceModel& source );
1123
 
    void operator = ( const NamespaceModel& source );
1124
 
    friend class CodeModel;
1125
 
};
1126
 
 
1127
 
 
1128
 
 
1129
 
 
1130
 
/**
1131
 
File model.
1132
 
Represents a file in the code model.
1133
 
Files in general contain classes, namespaces, functions,
1134
 
types, etc. Therefore FileModel is derived from NamespaceModel.
1135
 
 
1136
 
Instances of this class should be created using @ref CodeModel::create method.
1137
 
*/
1138
 
class FileModel: public NamespaceModel
1139
 
{
1140
 
protected:
1141
 
    /**Constructor.
1142
 
    @param model Code model which stores this item.*/
1143
 
    FileModel( CodeModel* model );
1144
 
 
1145
 
public:
1146
 
    /**A definition of safe pointer to the file model.*/
1147
 
    typedef FileDom Ptr;
1148
 
 
1149
 
    virtual bool isFile() const { return true; }
1150
 
 
1151
 
    virtual int groupId() const {
1152
 
        return m_groupId;
1153
 
    }
1154
 
    
1155
 
    virtual void setGroupId(int newId) {
1156
 
        m_groupId = newId;
1157
 
    }
1158
 
    
1159
 
    /** This function additionally does version-checking and
1160
 
        should be used instead of read when read should be called
1161
 
        from outside.
1162
 
    @return whether the read was successful */
1163
 
    
1164
 
    virtual void write( QDataStream& stream ) const;
1165
 
 
1166
 
    FileList wholeGroup() ;
1167
 
    
1168
 
    QStringList wholeGroupStrings() const;
1169
 
    
1170
 
    virtual void read( QDataStream& stream );
1171
 
 
1172
 
    ParseResultPointer parseResult() const;
1173
 
    void setParseResult( const ParseResultPointer& result );
1174
 
 
1175
 
  void update( const FileModel* i );
1176
 
private:
1177
 
    int m_groupId;
1178
 
    ParseResultPointer m_parseResult;
1179
 
    FileModel( const FileModel& );
1180
 
    void operator = ( const FileModel& );
1181
 
    friend class CodeModel;
1182
 
};
1183
 
 
1184
 
 
1185
 
/**
1186
 
Function (procedure) argument model.
1187
 
Represents an argument in the function.
1188
 
 
1189
 
Instances of this class should be created using @ref CodeModel::create method.
1190
 
*/
1191
 
class ArgumentModel: public CodeModelItem
1192
 
{
1193
 
protected:
1194
 
    ArgumentModel( CodeModel* model );
1195
 
 
1196
 
public:
1197
 
    /**A definition of safe pointer to the argument model.*/
1198
 
    typedef ArgumentDom Ptr;
1199
 
 
1200
 
    virtual bool isArgument() const { return true; }
1201
 
 
1202
 
    /**@return The type of this argument.*/
1203
 
    QString type() const;
1204
 
 
1205
 
    /**Sets the type of this argument.
1206
 
    @param type The type to set.*/
1207
 
    void setType( const QString& type );
1208
 
 
1209
 
    /**@return The default value of this argument.*/
1210
 
    QString defaultValue() const;
1211
 
 
1212
 
    /**Sets the default value of this argument.
1213
 
    @param defaultValue The default value to set.*/
1214
 
    void setDefaultValue( const QString& defaultValue );
1215
 
 
1216
 
    virtual void read( QDataStream& stream );
1217
 
    virtual void write( QDataStream& stream ) const;
1218
 
 
1219
 
    virtual void dump( std::ostream& file, bool recurse=false, QString Info="" );
1220
 
    
1221
 
private:
1222
 
    QString m_type;
1223
 
    QString m_defaultValue;
1224
 
 
1225
 
private:
1226
 
    ArgumentModel( const ArgumentModel& source );
1227
 
    void operator = ( const ArgumentModel& source );
1228
 
    friend class CodeModel;
1229
 
};
1230
 
 
1231
 
 
1232
 
/**
1233
 
Function model.
1234
 
Represents:
1235
 
- functions;
1236
 
- procedures;
1237
 
- class methods;
1238
 
.
1239
 
In languages that have separate function declarations and definitions (c++)
1240
 
this represents only function declarations. @see FunctionDefinitionModel 
1241
 
for a model of function definitions.
1242
 
 
1243
 
Instances of this class should be created using @ref CodeModel::create method.
1244
 
*/
1245
 
class FunctionModel: public CodeModelItem, public TemplateModelItem
1246
 
{
1247
 
protected:
1248
 
    /**Constructor.
1249
 
    @param model Code model which stores this item.*/
1250
 
    FunctionModel( CodeModel* model );
1251
 
 
1252
 
public:
1253
 
    /**A definition of safe pointer to the function model.*/
1254
 
    typedef FunctionDom Ptr;
1255
 
 
1256
 
    virtual bool isFunction() const { return true; }
1257
 
 
1258
 
    /**@return The scope of the function. Scope is a string list composed 
1259
 
    from names of parent functions, classes and namespaces.*/
1260
 
    QStringList scope() const { return m_scope; }
1261
 
 
1262
 
    /**Sets the scope of the function.
1263
 
    @param scope The scope to set.*/
1264
 
    void setScope( const QStringList& scope ) { m_scope = scope; }
1265
 
 
1266
 
    /**@return The access level of the function. Can return either values of type @ref CodeModelItem::Access or 
1267
 
    other integers if the function has other access level (for example pascal methods can have "published"
1268
 
    access level).*/
1269
 
    int access() const;
1270
 
 
1271
 
    /**Sets the access level of the function.
1272
 
    @param access The access level.*/
1273
 
    void setAccess( int access );
1274
 
 
1275
 
    /**@return true if the function is a signal.*/
1276
 
    bool isSignal() const;
1277
 
    /**Sets the function to be a signal.
1278
 
    @param isSignal The signal flag.*/
1279
 
    void setSignal( bool isSignal );
1280
 
 
1281
 
    /**@return true if the function is a slot.*/
1282
 
    bool isSlot() const;
1283
 
    /**Sets the function to be a slot.
1284
 
    @param isSlot The slot flag.*/
1285
 
    void setSlot( bool isSlot );
1286
 
 
1287
 
    /**@return true if the function is a virtual function.*/
1288
 
    bool isVirtual() const;
1289
 
    /**Sets the function to be a virtual function.
1290
 
    @param isVirtual The virtual flag.*/
1291
 
    void setVirtual( bool isVirtual );
1292
 
 
1293
 
    /**@return true if the function is a static function.*/
1294
 
    bool isStatic() const;
1295
 
    /**Sets the function to be a static function.
1296
 
    @param isStatic The static flag.*/
1297
 
    void setStatic( bool isStatic );
1298
 
 
1299
 
    /**@return true if the function is an inline function.*/
1300
 
    bool isInline() const;
1301
 
    /**Sets the function to be an inline function.
1302
 
    @param isInline The inline flag.*/
1303
 
    void setInline( bool isInline );
1304
 
 
1305
 
    /**@return true if the function is a constant function.*/
1306
 
    bool isConstant() const;
1307
 
    /**Sets the function to be a constant function.
1308
 
    @param isConstant The constant flag.*/
1309
 
    void setConstant( bool isConstant );
1310
 
 
1311
 
    /**@return true if the function is an abstract function.*/
1312
 
    bool isAbstract() const;
1313
 
    /**Sets the function to be an inline function.
1314
 
    @param isAbstract The abstract flag.*/
1315
 
    void setAbstract( bool isAbstract );
1316
 
 
1317
 
    /**@return The result type of a function.*/
1318
 
    QString resultType() const;
1319
 
    /**Sets the result type of a function.
1320
 
    @param type The type of a function result.*/
1321
 
    void setResultType( const QString& type );
1322
 
 
1323
 
    /**Gets the list of arguments being passed to the function.
1324
 
    If there are no arguments, then the list is empty.
1325
 
    @return The ArgumentList object that contains the arguments for this function.*/
1326
 
    ArgumentList argumentList();
1327
 
 
1328
 
    /**Gets the list of arguments being passed to the function.
1329
 
    If there are no arguments, then the list is empty.
1330
 
    @return The ArgumentList object that contains the arguments for this function.
1331
 
    @note This is a const version provided for convenience.*/
1332
 
    const ArgumentList argumentList() const;
1333
 
 
1334
 
    /**Adds an argument to the function.
1335
 
    @param arg The argument model to add as an argument to the function.
1336
 
    @return true if the addition was successful.*/
1337
 
    bool addArgument( ArgumentDom arg );
1338
 
 
1339
 
    /**Removes an argument from the function.
1340
 
    @param arg The argument model to remove from the function.*/
1341
 
    void removeArgument( ArgumentDom arg );
1342
 
 
1343
 
    virtual void read( QDataStream& stream );
1344
 
    virtual void write( QDataStream& stream ) const;
1345
 
 
1346
 
    virtual void dump( std::ostream& file, bool recurse=false, QString Info="" );
1347
 
    
1348
 
    void update( const FunctionModel* i );
1349
 
    bool canUpdate( const FunctionModel* i ) const;
1350
 
    
1351
 
private:
1352
 
    QStringList m_scope;
1353
 
    int m_access;
1354
 
 
1355
 
    union {
1356
 
        struct {
1357
 
            int m_signal : 1;
1358
 
            int m_slot : 1;
1359
 
            int m_virtual : 1;
1360
 
            int m_static : 1;
1361
 
            int m_inline : 1;
1362
 
            int m_constant : 1;
1363
 
            int m_abstract : 1;
1364
 
        } v;
1365
 
        int flags;
1366
 
    } d;
1367
 
 
1368
 
    QString m_resultType;
1369
 
    ArgumentList m_arguments;
1370
 
 
1371
 
private:
1372
 
    FunctionModel( const FunctionModel& source );
1373
 
    void operator = ( const FunctionModel& source );
1374
 
    friend class CodeModel;
1375
 
};
1376
 
 
1377
 
/**
1378
 
Function model.
1379
 
Represents function definition for languages that have such.
1380
 
 
1381
 
Instances of this class should be created using @ref CodeModel::create method.
1382
 
*/
1383
 
class FunctionDefinitionModel: public FunctionModel
1384
 
{
1385
 
protected:
1386
 
    /**Constructor.
1387
 
    @param model Code model which stores this item.*/
1388
 
    FunctionDefinitionModel( CodeModel* model );
1389
 
 
1390
 
public:
1391
 
    /**A definition of safe pointer to the function definition model.*/
1392
 
    typedef FunctionDefinitionDom Ptr;
1393
 
 
1394
 
    virtual bool isFunctionDefinition() const { return true; }
1395
 
 
1396
 
private:
1397
 
    FunctionDefinitionModel( const FunctionDefinitionModel& source );
1398
 
    void operator = ( const FunctionDefinitionModel& source );
1399
 
    friend class CodeModel;
1400
 
};
1401
 
 
1402
 
 
1403
 
/**
1404
 
Variable model.
1405
 
Represents variables and class attributes.
1406
 
 
1407
 
Instances of this class should be created using @ref CodeModel::create method.
1408
 
*/
1409
 
class VariableModel: public CodeModelItem
1410
 
{
1411
 
protected:
1412
 
    /**Constructor.
1413
 
    @param model Code model which stores this item.*/
1414
 
    VariableModel( CodeModel* model );
1415
 
 
1416
 
public:
1417
 
    /**A definition of safe pointer to the variable model.*/
1418
 
    typedef VariableDom Ptr;
1419
 
 
1420
 
    virtual bool isVariable() const { return true; }
1421
 
 
1422
 
    /**@return The access level of the variable. Can return either values of type @ref CodeModelItem::Access or 
1423
 
    other integers if the variable has other access level (for example pascal attributes can have "published"
1424
 
    access level).*/
1425
 
    int access() const;
1426
 
    /**Sets the access level of the variable.
1427
 
    @param access The access level.*/
1428
 
    void setAccess( int access );
1429
 
 
1430
 
    /**@return true if the variable is a static variable.*/
1431
 
    bool isStatic() const;
1432
 
    /**Sets the variable to be a static variable.
1433
 
    @param isStatic The static flag.*/
1434
 
    void setStatic( bool isStatic );
1435
 
 
1436
 
    /**@return A type of the variable.*/
1437
 
    QString type() const;
1438
 
    /**Sets the type of the variable.
1439
 
    @param type The type name.*/
1440
 
    void setType( const QString& type );
1441
 
 
1442
 
                /**@return If this is an enumerator, the enum it is part of, else an empty string. This is just a hack, necessary because EnumeratorModel is not used at all by the cpp-code-model. */
1443
 
                bool isEnumeratorVariable() const;
1444
 
 
1445
 
                void setEnumeratorVariable( bool b );
1446
 
 
1447
 
    virtual void read( QDataStream& stream );
1448
 
    virtual void write( QDataStream& stream ) const;
1449
 
 
1450
 
    virtual void dump( std::ostream& file, bool recurse=false, QString Info="" );
1451
 
 
1452
 
    void update( const VariableModel* i );
1453
 
    bool canUpdate( const VariableModel* i ) const;
1454
 
    
1455
 
private:
1456
 
    int m_access;
1457
 
    int m_static;
1458
 
    QString m_type;
1459
 
                int m_isEnumeratorVariable;
1460
 
 
1461
 
private:
1462
 
    VariableModel( const VariableModel& source );
1463
 
    void operator = ( const VariableModel& source );
1464
 
    friend class CodeModel;
1465
 
};
1466
 
 
1467
 
 
1468
 
/**
1469
 
Enum model.
1470
 
Represents enums.
1471
 
 
1472
 
Instances of this class should be created using @ref CodeModel::create method.
1473
 
*/
1474
 
class EnumModel: public CodeModelItem
1475
 
{
1476
 
protected:
1477
 
    /**Constructor.
1478
 
    @param model Code model which stores this item.*/
1479
 
    EnumModel( CodeModel* model );
1480
 
 
1481
 
public:
1482
 
    /**A definition of safe pointer to the enum model.*/
1483
 
    typedef EnumDom Ptr;
1484
 
 
1485
 
    virtual bool isEnum() const { return true; }
1486
 
 
1487
 
    /**@return The access level of the enum. Can return either values 
1488
 
    of type @ref CodeModelItem::Access or other integers if the enum has other access level.*/
1489
 
    int access() const;
1490
 
    /**Sets the access level of the enum.
1491
 
    @param access The access level.*/
1492
 
    void setAccess( int access );
1493
 
    
1494
 
    /**@return The list of enumerators in this enum.*/
1495
 
    EnumeratorList enumeratorList();
1496
 
    /**@return The list of enumerators in this enum.
1497
 
    @note This is a const version provided for convenience.*/
1498
 
    const EnumeratorList enumeratorList() const;
1499
 
    /**Adds an enumerator to the model.
1500
 
    @param e The enumerator model to add.*/
1501
 
    void addEnumerator( EnumeratorDom e );
1502
 
    /**Removes an enumerator from the model.
1503
 
    @param e The enumerator model to remove.*/
1504
 
    void removeEnumerator( EnumeratorDom e );
1505
 
 
1506
 
    virtual void read( QDataStream& stream );
1507
 
    virtual void write( QDataStream& stream ) const;
1508
 
 
1509
 
    ///The dump-function is not ready yet
1510
 
    virtual void dump( std::ostream& file, bool recurse=false, QString Info="" );
1511
 
 
1512
 
    void update( const EnumModel* i );
1513
 
    bool canUpdate( const EnumModel* i ) const;
1514
 
    
1515
 
private:
1516
 
    int m_access;
1517
 
    QMap<QString, EnumeratorDom> m_enumerators;
1518
 
 
1519
 
private:
1520
 
    EnumModel( const EnumModel& source );
1521
 
    void operator = ( const EnumModel& source );
1522
 
    friend class CodeModel;
1523
 
};
1524
 
 
1525
 
 
1526
 
/**
1527
 
Enumerator model.
1528
 
Represents enumerators. Enums consist of enumerators, for example in code:
1529
 
@code
1530
 
enum Type { A, B, C};
1531
 
@endcode
1532
 
Type is represented as EnumModel;\n
1533
 
A, B, C are represented with EnumeratorModel.
1534
 
 
1535
 
Instances of this class should be created using @ref CodeModel::create method.
1536
 
*/
1537
 
class EnumeratorModel: public CodeModelItem
1538
 
{
1539
 
protected:
1540
 
    /**Constructor.
1541
 
    @param model Code model which stores this item.*/
1542
 
    EnumeratorModel( CodeModel* model );
1543
 
 
1544
 
public:
1545
 
    /**A definition of safe pointer to the enumerator model.*/
1546
 
    typedef EnumeratorDom Ptr;
1547
 
 
1548
 
    virtual bool isEnumerator() const { return true; }
1549
 
    
1550
 
    /**@return The value of an enumerator.*/
1551
 
    QString value() const;
1552
 
    /**Sets the value of an enumerator.
1553
 
    @param value The value.*/
1554
 
    void setValue( const QString& value );
1555
 
 
1556
 
    virtual void read( QDataStream& stream );
1557
 
    virtual void write( QDataStream& stream ) const;
1558
 
 
1559
 
    virtual void dump( std::ostream& file, bool recurse=false, QString Info="" );
1560
 
    
1561
 
private:
1562
 
    QString m_value;
1563
 
    
1564
 
private:
1565
 
    EnumeratorModel( const EnumeratorModel& source );
1566
 
    void operator = ( const EnumeratorModel& source );
1567
 
    friend class CodeModel;
1568
 
};
1569
 
 
1570
 
 
1571
 
/**
1572
 
Type alias model.
1573
 
Represents type aliases (like subtypes/derived types in Ada and typedefs in c++).
1574
 
*/
1575
 
class TypeAliasModel: public CodeModelItem
1576
 
{
1577
 
protected:
1578
 
    /**Constructor.
1579
 
    @param model Code model which stores this item.*/
1580
 
    TypeAliasModel( CodeModel* model );
1581
 
 
1582
 
public:
1583
 
    /**A definition of safe pointer to the type alias model.*/
1584
 
    typedef TypeAliasDom Ptr;
1585
 
 
1586
 
    virtual bool isTypeAlias() const { return true; }
1587
 
    
1588
 
    /**@return The actual type of an alias.*/
1589
 
    QString type() const;
1590
 
    /**Sets the type of an alias.
1591
 
    @param type The type name.*/
1592
 
    void setType( const QString& type );
1593
 
    
1594
 
    virtual void read( QDataStream& stream );
1595
 
    virtual void write( QDataStream& stream ) const;
1596
 
 
1597
 
    
1598
 
    virtual void dump( std::ostream& file, bool recurse=false, QString Info="" );
1599
 
    
1600
 
    void update( const TypeAliasModel* i );
1601
 
    bool canUpdate( const TypeAliasModel* i ) const;
1602
 
 
1603
 
private:
1604
 
    QString m_type;
1605
 
    
1606
 
private:
1607
 
    TypeAliasModel( const TypeAliasModel& source );
1608
 
    void operator = ( const TypeAliasModel& source );
1609
 
    friend class CodeModel;
1610
 
};
1611
 
 
1612
 
#endif