Re: Problem with STL
- From: "Lloyd Dupont" <net.galador@ld>
- Date: Thu, 13 Jul 2006 21:54:50 +1000
1st: forget about char* comparison, pointer comparison is most appropriate!
2nd: thanks for your sample anyway, it taught me some bits about STL I might
find handy in the future.
3rd: For the present, as I indicate in a previous post to save you the time
to answer, I already solved the problem with a C Hastable implementation I
wrote.
"Carl Daniel [VC++ MVP]" <cpdaniel_remove_this_and_nospam@xxxxxxxxxxxxxxx>
wrote in message news:OYtVcmbpGHA.1796@xxxxxxxxxxxxxxxxxxxxxxx
Tom' already pointed out how to deal with your "map *" issue. From what
you've shown here, there's absolutely no need for you to store a pointer
to a map in the first place. Why complicate matters by storing a pointer
to a map? Also, when using the C++ standard library, liberal use of
typedefs will greatly increase the maintainability and understandability
of your code - not to mention saving you typing.
-cd
// uncompiled code - typos may be lurking
// borrowing from Tom's reply...
struct string_less_t
{
bool operator()(char const* lhs, char const* rhs) const
{
return std::strcmp(lhs, rhs) < 0;
}
};
typedef std::map<const char*, SEL, string_less_t> sel_map_t;
typedef std::map<SEL, IMP> imp_map_t;
typedef imp_map_t* imp_map_ptr_t;
typedef std::map<OClass, imp_map_t> class_map_t;
static sel_map_t map_sels;
static class_map_t map_imps;
void id::GetImpAlways(char char* name, SEL& sel, IMP& imp)
{
if( !_handle )
throw gcnew ObjectDisposedException(Class()->Name);
if(map_sels.count(name) == 0)
{
sel = sel_register_name(name);
map_sels[name] = sel;
}
else
{
sel = map_sels[name];
}
// not optimal - map_imps is searched twice, but the optimal
// code is very ugly and harder to understand
if(map_imps.count(_handle->class_pointer) == 0)
map_imps[_handle->class_pointer] = imp_map_t();
imp_map_ptr_t class_imps = &map_imps[_handle->class_pointer];
if(class_imps->count(sel) == 0)
{
imp = get_imp(_handle->class_pointer, sel);
if( !imp )
throw gcnew ObjectiveCException("No such method");
(*class_imps)[sel] = imp;
}
else
{
imp = (*class_imps)[sel];
}
}
.
- References:
- Problem with STL
- From: Lloyd Dupont
- Re: Problem with STL
- From: Carl Daniel [VC++ MVP]
- Problem with STL
- Prev by Date: Re: Problem with STL
- Next by Date: Need advice on the best way to intertwine fixed size 'C' data blocks into managed classes.
- Previous by thread: Re: Problem with STL
- Next by thread: Cannot resolve compiler error "A Sealed class cannot be abstract"
- Index(es):
Relevant Pages
|