Search code examples
c++visual-c++rhapsody

Replace an element in OMUMap(IBM Rational Rhapsody )


I want to overwrite an element corresponding to an key with new value. What function I can use for this?

I tried by calling fun

myMap.add(key, value)

But this is not replacing the value already stored in map.


Solution

  • add() should work, here is an example:

    OMUMap myMap;
    char key1[] = "key-1";
    char key2[] = "key-2";
    
    /* initialize map */
    myMap.add(static_cast<void*>(key1), static_cast<void*>("foo"));
    myMap.add(static_cast<void*>(key2), static_cast<void*>("bar"));
    
    std::cout << key1 << ": " << static_cast<char*>(myMap.getAt(key1)) << std::endl;
    std::cout << key2 << ": " << static_cast<char*>(myMap.getAt(key2)) << std::endl;
    
    /* replace 'key-1' value */                    
    myMap.add(static_cast<void*>(key1), static_cast<void*>("bazzz"));
    
    std::cout << key1 << ": " << static_cast<char*>(myMap.getAt(key1)) << std::endl;
    std::cout << key2 << ": " << static_cast<char*>(myMap.getAt(key2)) << std::endl;
    

    Output:

    key-1: foo
    key-2: bar
    key-1: bazzz
    key-2: bar