Discussion:
fltk1.3 namespace in fluid
Gonzalo Garramuno
2013-03-20 18:25:31 UTC
Permalink
I am trying to port my software from flkt2 to fltk1.3. However fluid1.3 complains due to lacking namespaces. Any chance of adding namespaces to fluid1.3 or a work-around?
Greg Ercolano
2013-03-20 20:51:12 UTC
Permalink
Post by Gonzalo Garramuno
I am trying to port my software from flkt2 to fltk1.3.
However fluid1.3 complains due to lacking namespaces.
Any chance of adding namespaces to fluid1.3 or a work-around?
To use a namespace, I'd think New->Code->Declaration, and set it to:

using namespace whatever;

..and to define a namespace, I guess you might have to do
something like put:

#include "foo-namespace-start.h"
...
#include "foo-namespace-end.h"

..where foo-namespace-start.h contains: namespace foo {
..and foo-namespace-end.h contains: };

Sorry I can't think of anything better; looks like fluid needs to
be modified, because New->Code->Declaration complains about the unclosed brace.
Probably an easy fix to have the Declaration input check be ignored if there's
a 'namespace' command..
Greg Ercolano
2013-03-20 21:26:19 UTC
Permalink
Post by Greg Ercolano
Sorry I can't think of anything better; looks like fluid needs to
be modified, because New->Code->Declaration complains about the unclosed brace.
I don't know fluid's code well at all, but it looks like the 'code check'
is due to the Fl_Decl_Type::open() method calling c_check() in fluid/Fl_Function_Type.cxx.

Perhaps an easy hack is to modify this line in Fl_Decl_Type::open():

message = c_check(c&&c[0]=='#' ? c+1 : c);

..to instead read something like:

if ( !strncmp(c,"namespace",9) &&
!strcmp(c,"};") ) message = c_check(c&&c[0]=='#' ? c+1 : c);

Then you can probably use New->Code->Declaration to start a namespace:

namespace foo {

..and a separate one to end it with:

};

I'm not sure if there are checks for this elsewhere in the code.
I think Matt and Bill are our resident fluid experts.
Greg Ercolano
2013-03-20 22:06:10 UTC
Permalink
Post by Greg Ercolano
message = c_check(c&&c[0]=='#' ? c+1 : c);
if ( !strncmp(c,"namespace",9) &&
!strcmp(c,"};") ) message = c_check(c&&c[0]=='#' ? c+1 : c);
Hmm, this should actually work; replace the "message = .." line with:

if (strncmp(c,"namespace",9)==0 || strncmp(c,"};",2)==0) { message = 0; }
else { message = c_check(c&&c[0]=='#' ? c+1 : c); }

I actually tested it this time; my original post wasn't checked,
and wasn't right.

This mod allows you to include a comment after the }; so you can
do something like:

namespace foo {

..and:

}; // end namespace foo

..without getting errors.

The above change is still a hack, it would take some work probably
to 'do it right', though I'm not sure what 'right' should be.
Greg Ercolano
2013-03-21 18:03:41 UTC
Permalink
Post by Gonzalo Garramuno
I am trying to port my software from flkt2 to fltk1.3.
However fluid1.3 complains due to lacking namespaces.
Any chance of adding namespaces to fluid1.3 or a work-around?
Gonzalo, I've opened STR #2936 for this feature request,
so that it doesn't get lost.
MacArthur, Ian (Selex ES, UK)
2013-03-21 18:24:00 UTC
Permalink
Post by Greg Ercolano
Post by Gonzalo Garramuno
I am trying to port my software from flkt2 to fltk1.3.
However fluid1.3 complains due to lacking namespaces.
Any chance of adding namespaces to fluid1.3 or a work-around?
Gonzalo, I've opened STR #2936 for this feature request,
so that it doesn't get lost.
Oh, was Gonzalo asking whether fluid could support namespaces? I had thought he was asking if fltk-1.3 itself would have namespaces (which for compatibility I guess it can't).

I suppose in fluid a namespace might be entered a bit like a grouping widget, such that other entities would be declared nested inside it? Is that the sort of thing?




Selex ES Ltd
Registered Office: Sigma House, Christopher Martin Road, Basildon, Essex SS14 3EL
A company registered in England & Wales. Company no. 02426132
********************************************************************
This email and any attachments are confidential to the intended
recipient and may also be privileged. If you are not the intended
recipient please delete it from your system and notify the sender.
You should not copy it or use it for any purpose nor disclose or
distribute its contents to any other person.
********************************************************************
Greg Ercolano
2013-03-21 20:38:30 UTC
Permalink
Post by MacArthur, Ian (Selex ES, UK)
Oh, was Gonzalo asking whether fluid could support namespaces?
I suppose in fluid a namespace might be entered a bit like a grouping widget,
such that other entities would be declared nested inside it? Is that the sort of thing?
Right, I think so; quoting the OP:
"Any chance of adding namespaces to fluid1.3"

..and I can certainly see the need for it, if one wanted to create
a widget or suite of tools in fluid attached to a namespace, or be able
to have multiple namespaces.

And yes, I think both the thing we use in fluid now for "Declaration Block"
could work for namespaces, as well as allowing a "single declaration"
to open and close should be possible too.
Post by MacArthur, Ian (Selex ES, UK)
I had thought he was asking if fltk-1.3 itself would have namespaces (which for compatibility I guess it can't).
Right, I don't think he's asking for an API change.

Roman Kantor
2013-03-21 20:34:54 UTC
Permalink
I am using namespaces in fluid, although with some tricks. Fluid complains (and does not accept) lines with open "{" brackets so first I have defined macros

#define NAMESPACE_START(name) namespace name {
#define NAMESPACE_END }

and then use these macros as

1) either in "declaration block" and putting all your code in that declaration block and switch property of that declaration block to "in header and source file"

2) at the beginning and end of fluid files in simple "declarations" but you need to do it twice, one for option "include in header file" and one for "include
in source file" as there is no option to "include in both" for simple declarations.


R.
Loading...