Debian Codegraph @

CodeLite/comment_parser.h

raw
1 //////////////////////////////////////////////////////////////////////////////
2 //////////////////////////////////////////////////////////////////////////////
3 //
4 // copyright : (C) 2009 by Eran Ifrah
5 // file name : comment_parser.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
26 #ifndef COMMENT_PARSER_H
27 #define COMMENT_PARSER_H
28
29 #include <map>
30 #include <string>
31 #include "codelite_exports.h"
32 #include "smart_ptr.h"
33
34 class WXDLLIMPEXP_CL CommentParseResult
35 {
36 private:
37 std::map<size_t, std::string> m_comments;
38 std::string m_filename;
39 public:
40 typedef SmartPtr<CommentParseResult> Ptr_t;
41
42 public:
43 void addComment(const std::string& comment, size_t line, bool cppComment)
44 {
45 // try to group this comment with the one above it
46 std::string cmt = comment;
47 if(cppComment && line) {
48 size_t prevLine = line - 1;
49 std::map<size_t, std::string>::iterator iter = m_comments.find(prevLine);
50 if(iter != m_comments.end()) {
51 cmt = iter->second;
52 cmt += "\n";
53 cmt += comment;
54
55 // remove the previous comment from the map
56 m_comments.erase(iter);
57 }
58 }
59 m_comments[line] = cmt;
60 }
61
62 std::string getCommentForLine(size_t line) const
63 {
64 std::map<size_t, std::string>::const_iterator iter = m_comments.find(line);
65 if(iter == m_comments.end()) return "";
66 return iter->second;
67 }
68
69 void print()
70 {
71 std::map<size_t, std::string>::const_iterator iter = m_comments.begin();
72 for(; iter != m_comments.end(); iter++) {
73 printf("Line : %u\n", (unsigned int)iter->first);
74 printf("Comment:\n%s\n", iter->second.c_str());
75 }
76 }
77
78 void setFilename(const std::string& filename) { m_filename = filename; }
79
80 const std::string& getFilename() const { return m_filename; }
81
82 void clear()
83 {
84 m_comments.clear();
85 m_filename.clear();
86 }
87 };
88
89 extern WXDLLIMPEXP_CL int ParseComments(const char* filePath, CommentParseResult& comments);
90
91 #endif // COMMENT_PARSER_H