~ubuntu-branches/ubuntu/lucid/codelite/lucid

« back to all changes in this revision

Viewing changes to CodeLite/entry.h

  • Committer: Bazaar Package Importer
  • Author(s): Chow Loong Jin
  • Date: 2009-01-12 15:46:55 UTC
  • Revision ID: james.westby@ubuntu.com-20090112154655-sdynrljcb6u167yw
Tags: upstream-1.0.2674+dfsg
ImportĀ upstreamĀ versionĀ 1.0.2674+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//////////////////////////////////////////////////////////////////////////////
 
2
//////////////////////////////////////////////////////////////////////////////
 
3
//
 
4
// copyright            : (C) 2008 by Eran Ifrah                            
 
5
// file name            : entry.h              
 
6
//                                                                          
 
7
// -------------------------------------------------------------------------
 
8
// A                                                                        
 
9
//              _____           _      _     _ _                            
 
10
//             /  __ \         | |    | |   (_) |                           
 
11
//             | /  \/ ___   __| | ___| |    _| |_ ___                      
 
12
//             | |    / _ \ / _  |/ _ \ |   | | __/ _ )                    
 
13
//             | \__/\ (_) | (_| |  __/ |___| | ||  __/                     
 
14
//              \____/\___/ \__,_|\___\_____/_|\__\___|                     
 
15
//                                                                          
 
16
//                                                  F i l e                 
 
17
//                                                                          
 
18
//    This program is free software; you can redistribute it and/or modify  
 
19
//    it under the terms of the GNU General Public License as published by  
 
20
//    the Free Software Foundation; either version 2 of the License, or     
 
21
//    (at your option) any later version.                                   
 
22
//                                                                          
 
23
//////////////////////////////////////////////////////////////////////////////
 
24
//////////////////////////////////////////////////////////////////////////////
 
25
 #ifndef CODELITE_ENTRY_H
 
26
#define CODELITE_ENTRY_H
 
27
 
 
28
#include "db_record.h"
 
29
#include <wx/treectrl.h>
 
30
#include "readtags.h"
 
31
#include <wx/string.h>
 
32
#include <map>
 
33
#include "smart_ptr.h"
 
34
 
 
35
#ifdef WXMAKINGDLL_CODELITE
 
36
#    define WXDLLIMPEXP_CL WXEXPORT
 
37
#elif defined(WXUSINGDLL_CODELITE)
 
38
#    define WXDLLIMPEXP_CL WXIMPORT
 
39
#else /* not making nor using FNB as DLL */
 
40
#    define WXDLLIMPEXP_CL
 
41
#endif // 
 
42
 
 
43
class TagsDatabase;
 
44
 
 
45
/**
 
46
 * TagEntry is a persistent object which is capable of storing and loading itself from 
 
47
 * various inputs:
 
48
 * - tagEntry (ctags structure)
 
49
 * - wxSQLite3ResultSet - from the database
 
50
 * 
 
51
 * It contains all the knowledge of storing and retrieving itself from the database
 
52
 *
 
53
 * \ingroup CodeLite
 
54
 * \version 1.0
 
55
 * first version        
 
56
 *
 
57
 * \date 11-11-2006
 
58
 * \author Eran
 
59
 */
 
60
class WXDLLIMPEXP_CL TagEntry : public DbRecord
 
61
{
 
62
        wxString m_path;                ///< Tag full path
 
63
        wxString m_file;                ///< File this tag is found
 
64
        int              m_lineNumber;  ///< Line number
 
65
        wxString m_pattern;             ///< A pattern that can be used to locate the tag in the file
 
66
        wxString m_kind;                ///< Member, function, class, typedef etc.
 
67
        wxString m_parent;              ///< Direct parent 
 
68
        wxTreeItemId m_hti;             ///< Handle to tree item, not persistent item
 
69
        wxString m_name;                ///< Tag name (short name, excluding any scope names)
 
70
        std::map<wxString, wxString> m_extFields; ///< Additional extension fields
 
71
        long    m_id;
 
72
        wxString m_scope;
 
73
        bool m_differOnByLineNumber;
 
74
        
 
75
public:
 
76
        /**
 
77
         * Construct a TagEntry from tagEntry struct
 
78
         * \param entry Tag entry
 
79
         */
 
80
        TagEntry(const tagEntry& entry);
 
81
 
 
82
        /**
 
83
         * Default constructor.
 
84
         */
 
85
        TagEntry();     
 
86
 
 
87
        /**
 
88
         * Copy constructor.
 
89
         */
 
90
        TagEntry(const TagEntry& rhs);
 
91
        
 
92
        /**
 
93
         * Construct a tag entry from db record.
 
94
         * \param rs Result set
 
95
         */
 
96
        TagEntry(wxSQLite3ResultSet& rs);
 
97
 
 
98
        /**
 
99
         * \param rhs Source to copy from (right hand side)
 
100
         * \return this
 
101
         */
 
102
        TagEntry& operator=(const TagEntry& rhs);
 
103
 
 
104
        /**
 
105
         * Compare two TagEntry objects.
 
106
         * \param rhs Right hand side
 
107
         * \return true if identical, false otherwise
 
108
         */
 
109
        bool operator==(const TagEntry& rhs);
 
110
 
 
111
        /**
 
112
         *      Destructor
 
113
         */
 
114
        virtual ~TagEntry();
 
115
 
 
116
        /**
 
117
         * Construct a TagEntry from tagEntry struct.
 
118
         * \param entry Tag entry
 
119
         */
 
120
        void Create(const tagEntry& entry);
 
121
 
 
122
        /**
 
123
         * Construct a TagEntry from values.
 
124
         * \param fileName File name
 
125
         * \param name Tag name
 
126
         * \param lineNumber Tag line number
 
127
         * \param pattern Pattern
 
128
         * \param kind Tag kind (class, struct, etc)
 
129
         * \param extFields Map of extenstion fields (key:value)
 
130
         * \param project Project name
 
131
         */
 
132
        void Create(const wxString &fileName, 
 
133
                                const wxString &name, 
 
134
                                int lineNumber, 
 
135
                                const wxString &pattern, 
 
136
                                const wxString &kind, 
 
137
                                std::map<wxString, wxString>& extFields);
 
138
 
 
139
        /**
 
140
         * Test if this entry has been initialised.
 
141
         * \return true if this tag entry has been initialised 
 
142
         */
 
143
        const bool IsOk() const { return GetKind() != _T("<unknown>"); }
 
144
 
 
145
        /**
 
146
         * Test of this tag is a container (class, union, struct or namespace
 
147
         */
 
148
        const bool IsContainer() const;
 
149
        
 
150
        //------------------------------------------
 
151
        // Operations
 
152
        //------------------------------------------
 
153
        bool GetDifferOnByLineNumber() const {return m_differOnByLineNumber;}
 
154
        
 
155
        int GetId() const { return m_id; }
 
156
        void SetId(int id) { m_id = id;}
 
157
 
 
158
        const wxString& GetName() const { return m_name;}
 
159
        void SetName(const wxString& name) { m_name = name; }
 
160
 
 
161
        const wxString& GetPath() const { return m_path;}
 
162
        void SetPath(const wxString& path) { m_path = path; }
 
163
 
 
164
        const wxString& GetFile() const { return m_file;}
 
165
        void SetFile(const wxString& file) { m_file = file;}
 
166
 
 
167
        int GetLine() const { return m_lineNumber;}
 
168
        void SetLine(int line) { m_lineNumber = line; }
 
169
        
 
170
        wxString GetPattern();
 
171
        void SetPattern(const wxString& pattern) { m_pattern = pattern; }
 
172
 
 
173
        wxString GetKind() const;
 
174
        void SetKind(const wxString& kind) { m_kind = kind; }
 
175
 
 
176
        const wxString& GetParent() const { return m_parent; }
 
177
        void SetParent(const wxString& parent) { m_parent = parent; }
 
178
 
 
179
        wxTreeItemId& GetTreeItemId() { return m_hti; }
 
180
        void SetTreeItemId(wxTreeItemId& hti) { m_hti = hti; }
 
181
 
 
182
        wxString GetAccess() const { return GetExtField(_T("access"));}
 
183
        void SetAccess(const wxString &access){m_extFields[wxT("access")] = access;}
 
184
 
 
185
        wxString GetSignature() const { return GetExtField(_T("signature")); }
 
186
        void SetSignature(const wxString &sig) { m_extFields[wxT("signature")] = sig; }
 
187
        
 
188
        wxString GetInherits() const { return GetExtField(_T("inherits")); }
 
189
        wxString GetTyperef() const { return GetExtField(_T("typeref")); }
 
190
 
 
191
        const wxString &GetScope() const {return m_scope;}
 
192
        void SetScope(const wxString &scope){m_scope = scope;}
 
193
 
 
194
        /**
 
195
         * \return Scope name of the tag.
 
196
         * If path is empty in db or contains just the project name, it will return the literal <global>.
 
197
         * For project tags, an empty string is returned.
 
198
         */
 
199
        wxString GetScopeName() const;
 
200
 
 
201
        /**
 
202
         * Generate a Key for this tag based on its attributes
 
203
         * \return tag key 
 
204
         */
 
205
        wxString Key() const;
 
206
 
 
207
        /**
 
208
         * Generate a display name for this tag to be used by the symbol tree
 
209
         * \return tag display name 
 
210
         */
 
211
        wxString GetDisplayName() const;
 
212
 
 
213
        /**
 
214
         * Generate a full display name for this tag that includes:
 
215
         * full scope + name + signature
 
216
         * \return tag full display name
 
217
         */
 
218
        wxString GetFullDisplayName() const;
 
219
 
 
220
        /**
 
221
         * Return the actual name as described in the 'typeref' field
 
222
         * \return real name or wxEmptyString
 
223
         */
 
224
        wxString NameFromTyperef(wxString &templateInitList);
 
225
 
 
226
        /**
 
227
         * Return the actual type as described in the 'typeref' field
 
228
         * \return real name or wxEmptyString
 
229
         */
 
230
        wxString TypeFromTyperef() const;
 
231
        //------------------------------------------
 
232
        // Extenstion fields
 
233
        //------------------------------------------
 
234
        wxString GetExtField(const wxString& extField) const 
 
235
        { 
 
236
                std::map<wxString, wxString>::const_iterator iter = m_extFields.find(extField);
 
237
                if(iter == m_extFields.end())
 
238
                        return wxEmptyString;
 
239
                return iter->second;
 
240
        }
 
241
        
 
242
        //------------------------------------------
 
243
        // Misc
 
244
        //------------------------------------------
 
245
        void Print();
 
246
 
 
247
 
 
248
        //------------------------------------------
 
249
        // Database operations
 
250
        //------------------------------------------
 
251
        /**
 
252
         * Save this record into db.
 
253
         * \param insertPreparedStmnt Prepared statement for insert operation
 
254
         * \return TagOk, TagExist, TagError
 
255
         */
 
256
        virtual int Store(wxSQLite3Statement& insertPreparedStmnt, TagsDatabase *db);
 
257
 
 
258
        /**
 
259
         * Update this record into db.
 
260
         * \param insertPreparedStmnt Prepared statement for insert operation
 
261
         * \return TagOk, TagError
 
262
         */
 
263
        virtual int Update(wxSQLite3Statement& updatePreparedStmnt);
 
264
 
 
265
        /**
 
266
         * Delete this record from db.
 
267
         * \param deletePreparedStmnt Prepared statement for delete operation
 
268
         * \return TagOk, TagError
 
269
         */
 
270
        virtual int Delete(wxSQLite3Statement& deletePreparedStmnt);
 
271
        
 
272
        /**
 
273
         * \return delete preapred statement
 
274
         */
 
275
        virtual wxString GetDeleteOneStatement();
 
276
 
 
277
        /**
 
278
         * \return update preapred statement
 
279
         */
 
280
        virtual wxString GetUpdateOneStatement();
 
281
 
 
282
        /**
 
283
         * \return insert preapred statement
 
284
         */
 
285
        virtual wxString GetInsertOneStatement();
 
286
 
 
287
 
 
288
private:
 
289
        /**
 
290
         * Update the path with full path (e.g. namespace::class)
 
291
         * \param path path to add
 
292
         */
 
293
        void UpdatePath(wxString & path);
 
294
        bool TypedefFromPattern(const wxString &tagPattern, const wxString &typedefName, wxString &name, wxString &templateInit);
 
295
};
 
296
 
 
297
typedef SmartPtr<TagEntry> TagEntryPtr;
 
298
#endif // CODELITE_ENTRY_H