C
christopher
Let me preface this with: I do have a good STL book on order from amazon as
we speak. $70..ouch, but as much as I ask STL questions on here...
In the meantime, I need a collection that can store an object that can be
looked up by two differant key types. Is there an existing class or
combination of classes that I can do this with?
Requirements:
I need a collection of elements with the following association:
MyClass * - guarenteed to point to a unique MyClass object on the heap
void * - optional, NULL or any object the user desires
std::string - optional, can be empty or a name of the association
Now MyClass is unique, so it is a canidate for being a key, but it is really
the thing I want to store so it is more of a value.
The other two are optional, so they can be keys, using a multimap it wouldnt
matter if they are NULL or empty or not.
The purpose of the collection is not to provide lookup, but rather to act
upon multiple MyClass's at once.
I came up with the following
MyClassSet
{
public:
..
someError Insert(MyClass * myclass, void * associated object = NULL,
std::string name = std::string("unnamed");
// Arg, I really need to be able to remove by these two!
someError Remove(MyClass *);
someError Remove(std::string);
// Perform an operation on ALL the MyClasses in the set.
void DoSomething();
// Get some kind of iterator for MyClassSet...this will be a seperate
newsgroup question I am sure
someIteratorThing GetNextElement();
// get the MyClass * and the void * associated with the string name
INeedToReturnTwoThings! GetMyClassByName(std::string)
private:
std::multimap<std::string, MyClass *>
std::multimap<MyClass *, void *>
}
The above has alot of problems I am sure you can see.
I was also thinking of using typdef and struct to make some type that has
all three types that are associated, but then what am I going to use for the
lookup?
I also thought about using templates to get rid of the void *, but the user
needs to have differant object types in the same MyClassSet, because MyClass
* can be associated with anything.
Can you help me get my head around this?
we speak. $70..ouch, but as much as I ask STL questions on here...
In the meantime, I need a collection that can store an object that can be
looked up by two differant key types. Is there an existing class or
combination of classes that I can do this with?
Requirements:
I need a collection of elements with the following association:
MyClass * - guarenteed to point to a unique MyClass object on the heap
void * - optional, NULL or any object the user desires
std::string - optional, can be empty or a name of the association
Now MyClass is unique, so it is a canidate for being a key, but it is really
the thing I want to store so it is more of a value.
The other two are optional, so they can be keys, using a multimap it wouldnt
matter if they are NULL or empty or not.
The purpose of the collection is not to provide lookup, but rather to act
upon multiple MyClass's at once.
I came up with the following
MyClassSet
{
public:
..
someError Insert(MyClass * myclass, void * associated object = NULL,
std::string name = std::string("unnamed");
// Arg, I really need to be able to remove by these two!
someError Remove(MyClass *);
someError Remove(std::string);
// Perform an operation on ALL the MyClasses in the set.
void DoSomething();
// Get some kind of iterator for MyClassSet...this will be a seperate
newsgroup question I am sure
someIteratorThing GetNextElement();
// get the MyClass * and the void * associated with the string name
INeedToReturnTwoThings! GetMyClassByName(std::string)
private:
std::multimap<std::string, MyClass *>
std::multimap<MyClass *, void *>
}
The above has alot of problems I am sure you can see.
I was also thinking of using typdef and struct to make some type that has
all three types that are associated, but then what am I going to use for the
lookup?
I also thought about using templates to get rid of the void *, but the user
needs to have differant object types in the same MyClassSet, because MyClass
* can be associated with anything.
Can you help me get my head around this?