Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » VectorMap inside VectorMap
Re: VectorMap inside VectorMap [message #19933 is a reply to message #19924] Tue, 03 February 2009 17:58 Go to previous message
White_Owl is currently offline  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.
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Quick bi-array
Next Topic: Core package build flags
Goto Forum:
  


Current Time: Sun Aug 17 18:18:39 CEST 2025

Total time taken to generate the page: 0.04958 seconds