aboutsummaryrefslogtreecommitdiff
path: root/third_party/CppHeaderParser/README.txt
blob: 2c57cad825a4f9bad81f399e3072a43bf13f40fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
Python package "CppHeaderParser"
--------------------------------
**Purpose:** Parse C++ header files and generate a data structure representing the class

**Author:** Jashua Cloutier (jashuac@bellsouth.net)

**Licence:** BSD

**External modules required:** PLY

**Quick start**::

    #include <vector>
    #include <string>
    using namespace std;
    class SampleClass
    {
    public:
        SampleClass();
        /*!
         * Method 1
         */
        string meth1();
    
        ///
        /// Method 2 description
        ///
        /// @param v1 Variable 1
        ///
        int meth2(int v1);
    
        /**
         * Method 3 description
         *
         * \param v1 Variable 1
         * \param v2 Variable 2
         */
        void meth3(const string & v1, vector<string> & v2);
    
        /**********************************
         * Method 4 description
         *
         * @return Return value
         *********************************/
        unsigned int meth4();
    private:
        void * meth5(){return NULL};
    
        /// prop1 description
        string prop1;
        //! prop5 description
        int prop5;
    };
    namespace Alpha
    {
        class AlphaClass
        {
        public:
            AlphaClass();
    
            void alphaMethod();
    
            string alphaString;
        };
    
        namespace Omega
        {
            class OmegaClass
            {
            public:
                OmegaClass();
    
                string omegaString;
            };
        };
    }
    

**Python code**::

    #!/usr/bin/python
    import sys
    sys.path = ["../"] + sys.path
    import CppHeaderParser
    try:
        cppHeader = CppHeaderParser.CppHeader("SampleClass.h")
    except CppHeaderParser.CppParseError,  e:
        print e
        sys.exit(1)
    
    print "CppHeaderParser view of %s"%cppHeader
    
    sampleClass = cppHeader.classes["SampleClass"]
    print "Number of public methods %d"%(len(sampleClass["methods"]["public"]))
    print "Number of private properties %d"%(len(sampleClass["properties"]["private"]))
    meth3 = [m for m in sampleClass["methods"]["public"] if m["name"] == "meth3"][0] #get meth3
    meth3ParamTypes = [t["type"] for t in meth3["parameters"]] #get meth3s parameters
    print "Parameter Types for public method meth3 %s"%(meth3ParamTypes)
    
    print "\nReturn type for meth1:"
    print cppHeader.classes["SampleClass"]["methods"]["public"][1]["rtnType"]
    
    print "\nDoxygen for meth2:"
    print cppHeader.classes["SampleClass"]["methods"]["public"][2]["doxygen"]
    
    print "\nParameters for meth3:"
    print cppHeader.classes["SampleClass"]["methods"]["public"][3]["parameters"]
    
    print "\nDoxygen for meth4:"
    print cppHeader.classes["SampleClass"]["methods"]["public"][4]["doxygen"]
    
    print "\nReturn type for meth5:"
    print cppHeader.classes["SampleClass"]["methods"]["private"][0]["rtnType"]
    
    print "\nDoxygen type for prop1:"
    print cppHeader.classes["SampleClass"]["properties"]["private"][0]["doxygen"]
    
    print "\nType for prop5:"
    print cppHeader.classes["SampleClass"]["properties"]["private"][1]["type"]
    
    print "\nNamespace for AlphaClass is:"
    print cppHeader.classes["AlphaClass"]["namespace"]
    
    print "\nReturn type for alphaMethod is:"
    print cppHeader.classes["AlphaClass"]["methods"]["public"][0]["rtnType"]
    
    print "\nNamespace for OmegaClass is:"
    print cppHeader.classes["OmegaClass"]["namespace"]
    
    print "\nType for omegaString is:"
    print cppHeader.classes["AlphaClass"]["properties"]["public"][0]["type"]

**Output**::

    CppHeaderParser view of class SampleClass
    Inherits: 
    {
    public
        // Method
        {'name': 'SampleClass', 'parameters': [], 'rtnType': 'void'}
        {'doxygen': '/*!\n* Method 1\n*/', 'name': 'meth1', 'parameters': [], 'rtnType': 'string'}
        {'doxygen': '///\n/// Method 2 description\n///\n/// @param v1 Variable 1\n///', 'name': 'meth2', 'parameters': [{'type': 'int', 'name': 'v1', 'desc': 'Variable 1'}], 'rtnType': 'int'}
        {'doxygen': '/**\n* Method 3 description\n*\n* \\param v1 Variable 1\n* \\param v2 Variable 2\n*/', 'name': 'meth3', 'parameters': [{'type': 'const string &', 'name': 'v1', 'desc': 'Variable 1'}, {'type': 'vector<string> &', 'name': 'v2', 'desc': 'Variable 2'}], 'rtnType': 'void'}
        {'doxygen': '/**********************************\n* Method 4 description\n*\n* @return Return value\n*********************************/', 'name': 'meth4', 'parameters': [], 'rtnType': 'unsigned int'}
    protected
    private
        // Properties
        {'doxygen': '/// prop1 description', 'type': 'string', 'name': 'prop1'}
        {'doxygen': '//! prop5 description', 'type': 'int', 'name': 'prop5'}
        // Method
        {'name': 'meth5', 'parameters': [], 'rtnType': 'void *'}
    }
    class Alpha::AlphaClass
    Inherits: 
    {
    public
        // Properties
        {'type': 'string', 'name': 'alphaString'}
        // Method
        {'name': 'AlphaClass', 'parameters': [], 'rtnType': 'void'}
        {'name': 'alphaMethod', 'parameters': [], 'rtnType': 'void'}
    protected
    private
    }
    class Alpha::Omega::OmegaClass
    Inherits: 
    {
    public
        // Properties
        {'type': 'string', 'name': 'omegaString'}
        // Method
        {'name': 'OmegaClass', 'parameters': [], 'rtnType': 'void'}
    protected
    private
    }
    
    Number of public methods 5
    Number of private properties 2
    Parameter Types for public method meth3 ['const string &', 'vector<string> &']
    
    Return type for meth1:
    string
    
    Doxygen for meth2:
    ///
    /// Method 2 description
    ///
    /// @param v1 Variable 1
    ///
    
    Parameters for meth3:
    [{'type': 'const string &', 'name': 'v1', 'desc': 'Variable 1'}, {'type': 'vector<string> &', 'name': 'v2', 'desc': 'Variable 2'}]
    
    Doxygen for meth4:
    /**********************************
    * Method 4 description
    *
    * @return Return value
    *********************************/
    
    Return type for meth5:
    void *
    
    Doxygen type for prop1:
    /// prop1 description
    
    Type for prop5:
    int
    
    Namespace for AlphaClass is:
    Alpha
    
    Return type for alphaMethod is:
    void
    
    Namespace for OmegaClass is:
    Alpha::Omega
    
    Type for omegaString is:
    string
    


Contributors
------------
Chris Love