Mental Patient on Mon, 16 Jun 2003 15:07:09 -0400


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] C++ Development


On Mon, 2003-06-16 at 12:03, Kyle R. Burton wrote:

> The fact that they have "Development Status: Beta" in red right
> on the main page makes me less than confident about using it.
> 

Its worth trying maybe.....  or at least looking at for inspiration. I
dunno. 

> One thing that the Jakarta projects seem to have going for them is
> the fact that they have a large community of users.
> 
> The Jakarat Log4j download page:
> 
>   http://jakarta.apache.org/log4j/docs/download.html
> 

Yes, and java as a whole has a greater mind share as far as contributed
code goes. Its not quite on the level of say.... CPAN, but its good.

> Also lists 2 alternative ports to C++:
> 
>   http://log4cplus.sourceforge.net/
>   http://log4cpp.sourceforge.net/
> 
> log4cplus reports that the first 'production' release should be out
> by the 26h of July.  I suppose log4cpp looks like it could be a viable 
> candidate for logging support.
> 
> In the Java code it's easy to tie logging context to the class
> that is reqesting the logger:
> 
>   public class Foo {
>     Logger logger = Logger.getInstance( Foo.class.getName() );
>   }
> 
> In Perl it's just about the same (and can be easier with static
> methods that query caller()):
> 
>   our $logger = Logger::getInstance(__PACKAGE__);
>   # or, even easier:
>   our $logger = Logger::getInstance;
> 
>   # then to wrap it...
>   package Logger;
>   sub getInstance
>   {
>     my($context) = @_;
>     $context ||= (caller)[0];
>     return Log::Log4perl->get_logger($context);
>   }
> 
> How could this be done in C++?  Is there a preprocessor define for
> the current object?  I know about __FILE__, __LINE__ and __FUNCTION__.
> Is there some equivalent for the namesapce and/or the class name?

You probably know better than I do that reflection simply isn't in C++
the way it is in java. That said, I talked to a couple people on #C++
and a couple other people I know who do C++. I came up with a couple
links. All of it is hacky.... even compared to how perl does it:)

http://tinyurl.com/egdb and http://tinyurl.com/egd3

those both point to sourceforge CVS browsing that give you Object.H 
and Object.C respectively basically, you have a static class member  
that's a string containing the class name in it along with other code 
(like isType) is initialized by the TYPE_INFO macro (or V_TYPE_INFO 
for abstract classes) you just do TYPE_INFO(MyClass, Superclass) and 
it handles the rest. There's also some other terrible horrible evil 
magic there too ;) oh, you have to do TYPE_INIT(classname) in the .C  
file for the class, too (toplevel, not the constructor)

there's typeid().name(),  It's fine if you only wish to compare things  
But expect different results from different compilers; and GCC produces 
only cryptic names. However as long as they're consistant and you dont
expect humans to read them, they might work. 

The only reason RTTI was added to C++ in the first place was because 
it was simple to and the committee did not want vendors to add their 
own and claim it as "this great feature", which is just the opposite.
Obviously I've never actually used it, and from my first look... its a
little confusing :)
http://www.asingh.net/technical/rtti.html

here's a paper on other reflectionish type crap
http://www.garret.ru/~knizhnik/cppreflection/docs/reflect.html

Also keep in mind that I was multitasking as I composed this....

-- 
Mental (Mental@NeverLight.com)

Express yourself, just say yes


Attachment: signature.asc
Description: This is a digitally signed message part