Author Topic: template implementation  (Read 6912 times)

Offline Freem

  • Almost regular
  • **
  • Posts: 219
template implementation
« on: September 25, 2011, 07:27:47 pm »
Usually, it is possible to use F11 key to switch between headers and source files.

For templates files, it is not possible, as they don't have true implementation file (ie: no cpp file) but it is common to use a tpp (or whatever else) file to avoid spamming the header file.

The problem is that, by default, C::B do not recognize those files as CPP ones.
It disable the F11 key and find implementation/declarations.

Is it possible to force CB to recognize tpp files as cpp for templates? And if yes, how? (I am currently working on a library using nearly only templates... so it is a bit annoying)

[edit]
removed the dumb assertion about color syntax. Just have to add it in the maskfile list, in general editor options.
But maybe it could be added by default?
[/edit]
« Last Edit: September 25, 2011, 07:47:33 pm by Freem »

Offline Alpha

  • Developer
  • Lives here!
  • *****
  • Posts: 1513
Re: template implementation
« Reply #1 on: September 25, 2011, 07:49:49 pm »
I am not sure about the rest, but for highlighting, you could add *.tpp to the filemasks for C/C++ under the syntax highlighting configuration.

Edit: I guess you just noticed that as well.

Offline Freem

  • Almost regular
  • **
  • Posts: 219
Re: template implementation
« Reply #2 on: September 25, 2011, 11:36:38 pm »
that's true, thanks anyway :)

But there is still the rest, the most useful in fact.

Offline Alpha

  • Developer
  • Lives here!
  • *****
  • Posts: 1513
Re: template implementation
« Reply #3 on: September 27, 2011, 02:22:39 am »
Try this patch; it should register *.tpp as a source file, enabling header/source switching (warning, untested).
Code
Index: src/sdk/globals.cpp
===================================================================
--- src/sdk/globals.cpp (revision 7467)
+++ src/sdk/globals.cpp (working copy)
@@ -230,6 +230,7 @@
         ext.IsSameAs(FileFilters::CC_EXT) ||
         ext.IsSameAs(FileFilters::CPP_EXT) ||
         ext.IsSameAs(FileFilters::CXX_EXT) ||
+        ext.IsSameAs(FileFilters::TPP_EXT) ||
         ext.IsSameAs(FileFilters::S_EXT) ||
         ext.IsSameAs(FileFilters::SS_EXT) ||
         ext.IsSameAs(FileFilters::S62_EXT) ||
Index: src/sdk/filefilters.cpp
===================================================================
--- src/sdk/filefilters.cpp (revision 7467)
+++ src/sdk/filefilters.cpp (working copy)
@@ -159,6 +159,7 @@
 const wxString FileFilters::CC_EXT                       = _T("cc");
 const wxString FileFilters::CPP_EXT                      = _T("cpp");
 const wxString FileFilters::CXX_EXT                      = _T("cxx");
+const wxString FileFilters::TPP_EXT                      = _T("tpp");
 const wxString FileFilters::INL_EXT                      = _T("inl");
 const wxString FileFilters::H_EXT                        = _T("h");
 const wxString FileFilters::HH_EXT                       = _T("hh");

Offline Freem

  • Almost regular
  • **
  • Posts: 219
Re: template implementation
« Reply #4 on: September 28, 2011, 11:20:02 am »
I have think about a workaround: added a tpp folder which contains the tpp files, renamed as cpp.
Adding the "tpp/*.cpp" files in the project, uncheck "compile file" and "linking file" in "Build" tab of files properties.

It's not very nice because I don't like to use cpp extension, but it allow to use near every CB tools (except for auto completion, because it actually don't like templates)

But I will test your patch this evening, when I will be able to download CB source code.

Offline Alpha

  • Developer
  • Lives here!
  • *****
  • Posts: 1513
Re: template implementation
« Reply #5 on: September 28, 2011, 08:23:50 pm »
If it does not work, you could try this one; it includes more changes (but again, untested).
Code
Index: src/sdk/scripting/bindings/sc_consts.cpp
===================================================================
--- src/sdk/scripting/bindings/sc_consts.cpp (revision 7470)
+++ src/sdk/scripting/bindings/sc_consts.cpp (working copy)
@@ -206,6 +206,7 @@
         BIND_WXSTR_CONSTANT_NAMED(FileFilters::CC_EXT, "EXT_CC");
         BIND_WXSTR_CONSTANT_NAMED(FileFilters::CPP_EXT, "EXT_CPP");
         BIND_WXSTR_CONSTANT_NAMED(FileFilters::CXX_EXT, "EXT_CXX");
+        BIND_WXSTR_CONSTANT_NAMED(FileFilters::TPP_EXT, "EXT_TPP");
         BIND_WXSTR_CONSTANT_NAMED(FileFilters::INL_EXT, "EXT_INL");
         BIND_WXSTR_CONSTANT_NAMED(FileFilters::H_EXT, "EXT_H");
         BIND_WXSTR_CONSTANT_NAMED(FileFilters::HH_EXT, "EXT_HH");
@@ -242,6 +243,7 @@
         BIND_WXSTR_CONSTANT_NAMED(FileFilters::CC_DOT_EXT, "DOT_EXT_CC");
         BIND_WXSTR_CONSTANT_NAMED(FileFilters::CPP_DOT_EXT, "DOT_EXT_CPP");
         BIND_WXSTR_CONSTANT_NAMED(FileFilters::CXX_DOT_EXT, "DOT_EXT_CXX");
+        BIND_WXSTR_CONSTANT_NAMED(FileFilters::TPP_DOT_EXT, "DOT_EXT_TPP");
         BIND_WXSTR_CONSTANT_NAMED(FileFilters::H_DOT_EXT, "DOT_EXT_H");
         BIND_WXSTR_CONSTANT_NAMED(FileFilters::HH_DOT_EXT, "DOT_EXT_HH");
         BIND_WXSTR_CONSTANT_NAMED(FileFilters::HPP_DOT_EXT, "DOT_EXT_HPP");
Index: src/sdk/globals.cpp
===================================================================
--- src/sdk/globals.cpp (revision 7470)
+++ src/sdk/globals.cpp (working copy)
@@ -230,6 +230,7 @@
         ext.IsSameAs(FileFilters::CC_EXT) ||
         ext.IsSameAs(FileFilters::CPP_EXT) ||
         ext.IsSameAs(FileFilters::CXX_EXT) ||
+        ext.IsSameAs(FileFilters::TPP_EXT) ||
         ext.IsSameAs(FileFilters::S_EXT) ||
         ext.IsSameAs(FileFilters::SS_EXT) ||
         ext.IsSameAs(FileFilters::S62_EXT) ||
Index: src/sdk/filefilters.cpp
===================================================================
--- src/sdk/filefilters.cpp (revision 7470)
+++ src/sdk/filefilters.cpp (working copy)
@@ -159,6 +159,7 @@
 const wxString FileFilters::CC_EXT                       = _T("cc");
 const wxString FileFilters::CPP_EXT                      = _T("cpp");
 const wxString FileFilters::CXX_EXT                      = _T("cxx");
+const wxString FileFilters::TPP_EXT                      = _T("tpp");
 const wxString FileFilters::INL_EXT                      = _T("inl");
 const wxString FileFilters::H_EXT                        = _T("h");
 const wxString FileFilters::HH_EXT                       = _T("hh");
@@ -210,6 +211,7 @@
 const wxString FileFilters::CPP_DOT_EXT                      = _T('.') + FileFilters::CPP_EXT;
 const wxString FileFilters::INL_DOT_EXT                      = _T('.') + FileFilters::INL_EXT;
 const wxString FileFilters::CXX_DOT_EXT                      = _T('.') + FileFilters::CXX_EXT;
+const wxString FileFilters::TPP_DOT_EXT                      = _T('.') + FileFilters::TPP_EXT;
 const wxString FileFilters::H_DOT_EXT                        = _T('.') + FileFilters::H_EXT;
 const wxString FileFilters::HH_DOT_EXT                       = _T('.') + FileFilters::HH_EXT;
 const wxString FileFilters::HPP_DOT_EXT                      = _T('.') + FileFilters::HPP_EXT;
Index: src/include/filefilters.h
===================================================================
--- src/include/filefilters.h (revision 7470)
+++ src/include/filefilters.h (working copy)
@@ -83,6 +83,7 @@
     extern const DLLIMPORT wxString CC_EXT;
     extern const DLLIMPORT wxString CPP_EXT;
     extern const DLLIMPORT wxString CXX_EXT;
+    extern const DLLIMPORT wxString TPP_EXT;
     extern const DLLIMPORT wxString INL_EXT;
     extern const DLLIMPORT wxString H_EXT;
     extern const DLLIMPORT wxString HH_EXT;
@@ -123,6 +124,7 @@
     extern const DLLIMPORT wxString CC_DOT_EXT;
     extern const DLLIMPORT wxString CPP_DOT_EXT;
     extern const DLLIMPORT wxString CXX_DOT_EXT;
+    extern const DLLIMPORT wxString TPP_DOT_EXT;
     extern const DLLIMPORT wxString INL_DOT_EXT;
     extern const DLLIMPORT wxString H_DOT_EXT;
     extern const DLLIMPORT wxString HH_DOT_EXT;
Index: src/src/associations.cpp
===================================================================
--- src/src/associations.cpp (revision 7470)
+++ src/src/associations.cpp (working copy)
@@ -34,6 +34,7 @@
     { FileFilters::CC_EXT,              _T("C++ source file"),               4 },
     { FileFilters::CPP_EXT,             _T("C++ source file"),               4 },
     { FileFilters::CXX_EXT,             _T("C++ source file"),               4 },
+    { FileFilters::TPP_EXT,             _T("C++ source file"),               4 },
     { FileFilters::INL_EXT,             _T("C++ source file"),               4 },
 
     { FileFilters::H_EXT,               _T("Header file"),                   5 },