Re: (no subject)

Jon Watte <[email protected]> Wed, 16 Jun 2010 12:34:52 -0700
Newsgroups gmane.games.devel.sweng
Message-ID <[email protected]>
>
> Reflection in C++ would be nice. Now I have to do that manually with =
> macros which is kind of ok with some extra typing, but would be nicer to =
> have language support for it. In addition to variable name & type =
> exposure, reflection would need some mechanism to define custom =
> properties at member variable declaration though (e.g. hidden, mutable, =
> etc.) to make it really useful.
>
>
>

First, you might want to not use MS Word for e-mail to this list -- it
screws up the text pretty horribly.

Second, that request is akin to the request of custom cv-quals, which is
another peeve I've had with C++, which would make expressing certain things
about your code easier. For now, you can kind-of emulate some of the use
cases by wrapping in property templates.

If instead of "const" you could also declare a cv-qual named, say,
"main_thread_only," then you could declare variables as:

main_thread_only int foo;

just like you declare:

const int foo;

For now, you have to emulate it with templates:

thread_access<int, main_thread_only> foo;

(There's also the question about how the compiler and code can co-operate to
enforce whatever semantics you want to tie into your custom cv-qual)

Anyway, you can probably use this idea to make the variables you care about
"marked" already:

networkable<editable<int> > someCount;

The reason you'd still need static reflection, rather than just do it all
with templates as-is, is that the language has no way for a member to
discover its context/container. There's a lot of typing to make that doable:

struct MyReflectedStruct {
  member<MyReflectedStruct, networkable<editable<int> > > someCount;
  MyReflectedStruct()
    : someCount(this,
        networkable<editable<int> >(some_network_queue,
        editable<int>("Count of Some things")))
  {
  }
}

There's a lot of repetition there :-(

With more modern annotations and mark-up, that might look something like:

  struct MyReflectedStruct {
    struct_member,
    networked(lambda { return some_network_queue; }),
    editable("Count of Some things")
      int someCount;
  }

Look, ma, no repetition!

C# gets this mostly right with [Attributes]. Java and Python also has
support for this.

Sincerely,

jw

_______________________________________________
Sweng-Gamedev mailing list
[email protected]
http://lists.midnightryder.com/listinfo.cgi/sweng-gamedev-midnightryder.com