|
|
Home » U++ Library support » U++ Core » VectorMap inside VectorMap
VectorMap inside VectorMap [message #19924] |
Mon, 02 February 2009 23:08  |
White_Owl
Messages: 27 Registered: January 2009 Location: New York
|
Promising Member |
|
|
What is wrong with this code?
#include <Core/Core.h>
using namespace Upp;
class mycontainer: Moveable<mycontainer> {
public:
VectorMap<String, String> data;
};
VectorMap<String, mycontainer> vm;
CONSOLE_APP_MAIN
{
mycontainer ca = vm.GetAdd("First");
ca.data.FindPut("first-first", "aa");
ca.data.FindPut("first-second", "bb");
mycontainer cb = vm.GetAdd("First");
cb.data.FindPut("first-first", "cc"); // run-time error
cb.data.FindPut("first-second", "dd");
} Why do I get a run-time error in debug mode?
---------------------------
Fatal error
---------------------------
Assertion failed in C:/upp/uppsrc/Core/Vcont.h, line 18
Broken pick semantics
---------------------------
OK
---------------------------
|
|
|
|
|
Re: VectorMap inside VectorMap [message #19933 is a reply to message #19924] |
Tue, 03 February 2009 17:58   |
White_Owl
Messages: 27 Registered: January 2009 Location: New York
|
Promising Member |
|
|
Ok, here is the code which does exactly what I want:
#include <Core/Core.h>
using namespace Upp;
class mycontainer: Moveable<mycontainer> {
public:
VectorMap<String, String> data;
};
VectorMap<String, mycontainer> vm;
void define_word(const String& outer_key, const String& inner_key, const String& value) {
mycontainer *ca = vm.FindPtr(outer_key);
if(!ca)
ca = &(vm.Add(outer_key));
if(ca->data.Find(inner_key)>=0)
ca->data.RemoveKey(inner_key);
ca->data.Add(inner_key, value);
}
CONSOLE_APP_MAIN
{
define_word("First", "first-first", "aa");
puts(vm.Get("First").data.Get("first-first"));
puts("Sizeof(vm)=" + FormatInt(vm.GetCount()));
puts("Sizeof(vm{First}.data)=" + FormatInt(vm.Get("First").data.GetCount()));
define_word("First", "first-first", "bb");
puts(vm.Get("First").data.Get("first-first"));
puts("Sizeof(vm)=" + FormatInt(vm.GetCount()));
puts("Sizeof(vm{First}.data)=" + FormatInt(vm.Get("First").data.GetCount()));
} I think GetAdd()/FindPut and other "double" methods already have all this checking and removing old values. But I can not find which one of them actually does it without invalidating objects inside the container.
|
|
|
|
|
|
Goto Forum:
Current Time: Fri May 09 17:42:44 CEST 2025
Total time taken to generate the page: 0.01918 seconds
|
|
|