Code::Blocks Forums

Developer forums (C::B DEVELOPMENT STRICTLY!) => Development => Topic started by: oBFusCATed on April 17, 2012, 11:47:28 pm

Title: FindProjectFromFile refactoring
Post by: oBFusCATed on April 17, 2012, 11:47:28 pm
@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
Title: Re: FindProjectFromFile refactoring
Post by: ollydbg on April 18, 2012, 02:44:21 am
Code
+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. :)
Title: Re: FindProjectFromFile refactoring
Post by: MortenMacFly on April 18, 2012, 09:35:39 pm
Any comments are welcome. If there are no objections in the next week or so, I'll commit it. :-P
Fine with me.