News:

The new Release 25.03 is out! You can download binaries for Windows and many major Linux distros here .

Main Menu

FindProjectFromFile refactoring

Started by oBFusCATed, April 17, 2012, 11:47:28 PM

Previous topic - Next topic

oBFusCATed

@devs:
What do you think about this patch: http://cmpt.benbmp.org/codeblocks/patches/dbg/find_project_from_file_01.patch ?

The idea of it is to remove some code duplication and to make life of plugin writers easier. I plan to use this method in the gdb/mi plugin.
I'm not sure I like the signature of the method. I'd rather make it return a std::pair, so the users of the method have a in-code documentation that the method returns two values - a cbProject and a ProjectFile.

Any comments are welcome. If there are no objections in the next week or so, I'll commit it. :-P
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

ollydbg


+cbProject* ProjectManager::FindProjectForFile(const wxString& file, ProjectFile **resultFile,
+                                              bool isRelative, bool isUnixFilename)
+{
+    for (size_t i = 0; i < m_pProjects->GetCount(); ++i)
+    {
+        cbProject* prj = m_pProjects->Item(i);
+        ProjectFile *temp = prj->GetFileByFilename(file, isRelative, isUnixFilename);
+        if (temp)
+        {
+            if (resultFile)
+                *resultFile = temp;
+            return prj;
+        }
+    }
+    if (resultFile)
+        *resultFile = nullptr;
+    return nullptr;
+}


So, the first matching project is returned. Right? (The original code does the same thing)

Ok about other part. :)
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

MortenMacFly

Quote from: oBFusCATed on April 17, 2012, 11:47:28 PM
Any comments are welcome. If there are no objections in the next week or so, I'll commit it. :-P
Fine with me.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: [url="https://www.codeblocks.org/docs/main_codeblocks_en.html"]https://www.codeblocks.org/docs/main_codeblocks_en.html[/url]
C::B FAQ: [url="https://wiki.codeblocks.org/index.php?title=FAQ"]https://wiki.codeblocks.org/index.php?title=FAQ[/url]