Author Topic: FindProjectFromFile refactoring  (Read 5088 times)

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13406
    • Travis build status
FindProjectFromFile refactoring
« 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
(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!]

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6077
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: FindProjectFromFile refactoring
« Reply #1 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. :)
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.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9723
Re: FindProjectFromFile refactoring
« Reply #2 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.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ