Feature of STL map
-
Hi, In IBM open class library,we have a class called IKeySet which has to be replaced by map in STL as per IBM migration guide.But in eh IKeySet we have a provision to add an elelemnt with key as well as an element.(this feature it inherited from ICollection class which is equivalent to list or deque in STL). I am trying in vain to have this type with map also but dint succeed. Can you guys give some idea as how to implement this.That would pull me out of this soup.. Thanks Sasi
-
Hi, In IBM open class library,we have a class called IKeySet which has to be replaced by map in STL as per IBM migration guide.But in eh IKeySet we have a provision to add an elelemnt with key as well as an element.(this feature it inherited from ICollection class which is equivalent to list or deque in STL). I am trying in vain to have this type with map also but dint succeed. Can you guys give some idea as how to implement this.That would pull me out of this soup.. Thanks Sasi
-
Infact IKeyset inherited the feautures of ICollection( which is like list) and IAKeySet(its like map).SO we can add the elements of both with key (like in map)as well as just the element(liek in list). Hope this will suffice.Please look at the code below #include #include #include #include #include using namespace std; typedef const string& CIR; typedef enum { IEArgString, IEArgNumber, IEArgSpecial } IEArgType; class IEArg { public: //* Element name and value and embedded datatype. string name; string value; IEArgType dataType; //* Default constructor given name and value. IEArg(CIR n, CIR v) : name(n), value(v) { dataType = IEArgString; } IEArg(CIR n, CIR v, IEArgType t) : name(n), value(v), dataType(t) { } friend bool operator<(const IEArg& lhs, const IEArg& rhs); }; inline bool operator<(const IEArg& lhs, const IEArg& rhs) { if (lhs.name == rhs.name && lhs.value == rhs.value) return FALSE; else return TRUE; } typedef map IEArgList; inline CIR key(const IEArg& iea) { return iea.name; } typedef deque < IEArg > IEOArgList; typedef deque < IEOArgList > SUMMARY; main() { int days=10; IEArgList al; string where; string nam="1235"; string val="12"; // Maps and multimaps deal with pairs typedef pair entry; entry p0("Time",IEArg("1100","A")); entry p1("Time",IEArg("1234","A")); entry p2("Transaction",IEArg("4567","D")); entry p4("xransaction",IEArg("2345","B")); entry p3("ResultCode",IEArg("5678","C")); al.insert(p0); al.insert(p1); al.insert(p2); al.insert(p4); al.insert(p3); /******** I want add just IEArgList just liek a collection with out key ********/ IEArgList::iterator iter; for (iter = al.begin(); iter != al.end(); iter++) { cout<<"values are:"<<(*iter).first<<":"<<(*iter).second.value<<":"<<(*iter).second.name<
-
Infact IKeyset inherited the feautures of ICollection( which is like list) and IAKeySet(its like map).SO we can add the elements of both with key (like in map)as well as just the element(liek in list). Hope this will suffice.Please look at the code below #include #include #include #include #include using namespace std; typedef const string& CIR; typedef enum { IEArgString, IEArgNumber, IEArgSpecial } IEArgType; class IEArg { public: //* Element name and value and embedded datatype. string name; string value; IEArgType dataType; //* Default constructor given name and value. IEArg(CIR n, CIR v) : name(n), value(v) { dataType = IEArgString; } IEArg(CIR n, CIR v, IEArgType t) : name(n), value(v), dataType(t) { } friend bool operator<(const IEArg& lhs, const IEArg& rhs); }; inline bool operator<(const IEArg& lhs, const IEArg& rhs) { if (lhs.name == rhs.name && lhs.value == rhs.value) return FALSE; else return TRUE; } typedef map IEArgList; inline CIR key(const IEArg& iea) { return iea.name; } typedef deque < IEArg > IEOArgList; typedef deque < IEOArgList > SUMMARY; main() { int days=10; IEArgList al; string where; string nam="1235"; string val="12"; // Maps and multimaps deal with pairs typedef pair entry; entry p0("Time",IEArg("1100","A")); entry p1("Time",IEArg("1234","A")); entry p2("Transaction",IEArg("4567","D")); entry p4("xransaction",IEArg("2345","B")); entry p3("ResultCode",IEArg("5678","C")); al.insert(p0); al.insert(p1); al.insert(p2); al.insert(p4); al.insert(p3); /******** I want add just IEArgList just liek a collection with out key ********/ IEArgList::iterator iter; for (iter = al.begin(); iter != al.end(); iter++) { cout<<"values are:"<<(*iter).first<<":"<<(*iter).second.value<<":"<<(*iter).second.name<
-
Infact IKeyset inherited the feautures of ICollection( which is like list) and IAKeySet(its like map).SO we can add the elements of both with key (like in map)as well as just the element(liek in list). Hope this will suffice.Please look at the code below #include #include #include #include #include using namespace std; typedef const string& CIR; typedef enum { IEArgString, IEArgNumber, IEArgSpecial } IEArgType; class IEArg { public: //* Element name and value and embedded datatype. string name; string value; IEArgType dataType; //* Default constructor given name and value. IEArg(CIR n, CIR v) : name(n), value(v) { dataType = IEArgString; } IEArg(CIR n, CIR v, IEArgType t) : name(n), value(v), dataType(t) { } friend bool operator<(const IEArg& lhs, const IEArg& rhs); }; inline bool operator<(const IEArg& lhs, const IEArg& rhs) { if (lhs.name == rhs.name && lhs.value == rhs.value) return FALSE; else return TRUE; } typedef map IEArgList; inline CIR key(const IEArg& iea) { return iea.name; } typedef deque < IEArg > IEOArgList; typedef deque < IEOArgList > SUMMARY; main() { int days=10; IEArgList al; string where; string nam="1235"; string val="12"; // Maps and multimaps deal with pairs typedef pair entry; entry p0("Time",IEArg("1100","A")); entry p1("Time",IEArg("1234","A")); entry p2("Transaction",IEArg("4567","D")); entry p4("xransaction",IEArg("2345","B")); entry p3("ResultCode",IEArg("5678","C")); al.insert(p0); al.insert(p1); al.insert(p2); al.insert(p4); al.insert(p3); /******** I want add just IEArgList just liek a collection with out key ********/ IEArgList::iterator iter; for (iter = al.begin(); iter != al.end(); iter++) { cout<<"values are:"<<(*iter).first<<":"<<(*iter).second.value<<":"<<(*iter).second.name<
I can't understand what your code is supposed to be doing. Why not describe your basic data structures and what this collection is supposed to be used for? You obviously cannot make a map or a set of a type and then store things that are not actually instances of that type in the map or set. FWIW when you reply with code if you check the little box after the text box it will display the template definitions directly and not require us to 'view source' and generally mess about. Paul