<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Frage zu einer map]]></title><description><![CDATA[<p>Hallo Community,</p>
<p>ich erstelle eine map mit (string, eigeneKlasse). Im schriftlichen ausgedrückt:<br />
Ich lege werte in die Map mit dem Schlüsseln (B,C,D,E,F);</p>
<p>Später hole ich mir den const String-Schlüssel von 'B' ab und ändere dessen Inhalt z.B. auf 'X'.</p>
<p>Was zu dem ergebnis führt, das der Schlüsselwert in 'B' geändert wird, ich finde den Wert allerdings immernoch unter dem Schlüssel 'B' und nicht unter 'X'.</p>
<p>Soweit habe ich das schon getestet, bzw es ist klar das es nicht funktionieren kann ohne das die Sortierung 'aktuallisiert' wird.</p>
<p>Aber wollte es doch mal posten, evtl gibt es ja nen Trick oder doch einen Funktion die in der Liste die Key neu aktuallisiert, also eine Änderung der Sortierung ausführt.</p>
<p>Besten Dank schon mal für Anregungen, ich poste jetzt mal noch den Code:</p>
<p>// theClass - .h Datei</p>
<pre><code class="language-cpp">#ifndef __theClass__
#define __theClass__

// Header
#include &lt;wx/wx.h&gt;

class theClass
{
protected:
	wxString inhalt;
	const wxString* sort;

public:
	// ctor
	theClass();
	theClass(const wxString&amp; newInhalt);

	// dtor
	~theClass();

	// Get Inhalt
	wxString getInhalt() const;

	// Zeiger auf Sort Get()
	const wxString* GetSortPointer() const;

	// SortSet
	void SortSet(const wxString* newSort);

};
#endif // __theClass__
</code></pre>
<p>// theClass - .cpp Datei</p>
<pre><code class="language-cpp">// eigener Header
#include &quot;theClass.h&quot;

// Header aus Header
#include &lt;wx/wx.h&gt;

// ctor
theClass::theClass()
:inhalt(wxEmptyString)
,sort(0)
{
}
theClass::theClass( const wxString&amp; newInhalt)
:inhalt(newInhalt)
,sort(0)
{
}

// dtor
theClass::~theClass()
{
}

// Get Inhalt
wxString theClass::getInhalt() const
{
	return inhalt;
}

// Zeiger auf Sort Get()
const wxString* theClass::GetSortPointer() const
{
	return sort;
}

// SortSet
void theClass::SortSet(const wxString* newSort)
{
	sort = newSort;
}
</code></pre>
<p>// basic_frame - .cpp</p>
<pre><code class="language-cpp">// eigener header
#include &quot;basic_frame.h&quot;

// Header aus Header
#include &lt;wx/wx.h&gt;
#include &lt;wx/frame.h&gt;

// weitere Header
#include &lt;map&gt;
#include &quot;theClass.h&quot;

typedef std::map&lt;wxString, theClass&gt; mapStore;

BasicFrame::BasicFrame(const wxString &amp;title, const int &amp;xpos, const int &amp;ypos, const int &amp;width, const int &amp;hight)
:wxFrame( (wxFrame *)0, -1, title, wxPoint(xpos,ypos), wxSize(width,hight) )
{
	panel = new wxPanel(this);

	mapStore t;

	// Fünf Objecte
	theClass obj1(_T(&quot;Text of 1-A&quot;));
	theClass obj2(_T(&quot;Text of 2-B&quot;));
	theClass obj3(_T(&quot;Text of 3-C&quot;));
	theClass obj4(_T(&quot;Text of 4-D&quot;));
	theClass obj5(_T(&quot;Text of 5-E&quot;));

	// In die Liste
	t[_T(&quot;B&quot;)] = obj1;
	t[_T(&quot;C&quot;)] = obj2;
	t[_T(&quot;D&quot;)] = obj3;
	t[_T(&quot;E&quot;)] = obj4;
	t[_T(&quot;F&quot;)] = obj5;

	// Zeiger setzen
	for (mapStore::iterator it = t.begin(); it!=t.end(); it++)
	{
		it-&gt;second.SortSet(&amp;it-&gt;first);
	}

	// Element 1 Holen
	mapStore::iterator it = t.begin();

	// const abholen
	const wxString* b = it-&gt;second.GetSortPointer();

	// const wegcaste
	wxString* b1 = const_cast&lt;wxString*&gt;(b);

	// X an B zuweisen
	*b1 = _T(&quot;X&quot;);

	// &lt;--- hier müsste ich bei der map einen refresh ausführen // falls es sowas gibt

	//Liste neu sortieren
	it = t.find(_T(&quot;X&quot;));

	if (it != t.end())
	{
		wxMessageBox(it-&gt;second.getInhalt());
	}
	else
	{
		wxMessageBox(_T(&quot;Not Found&quot;));
	}

	bool allDone = true;
	allDone;
}

BasicFrame::~BasicFrame()
{
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/282333/frage-zu-einer-map</link><generator>RSS for Node</generator><lastBuildDate>Sun, 23 Aug 2026 07:13:22 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/282333.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 18 Feb 2011 08:48:06 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Frage zu einer map on Fri, 18 Feb 2011 08:48:06 GMT]]></title><description><![CDATA[<p>Hallo Community,</p>
<p>ich erstelle eine map mit (string, eigeneKlasse). Im schriftlichen ausgedrückt:<br />
Ich lege werte in die Map mit dem Schlüsseln (B,C,D,E,F);</p>
<p>Später hole ich mir den const String-Schlüssel von 'B' ab und ändere dessen Inhalt z.B. auf 'X'.</p>
<p>Was zu dem ergebnis führt, das der Schlüsselwert in 'B' geändert wird, ich finde den Wert allerdings immernoch unter dem Schlüssel 'B' und nicht unter 'X'.</p>
<p>Soweit habe ich das schon getestet, bzw es ist klar das es nicht funktionieren kann ohne das die Sortierung 'aktuallisiert' wird.</p>
<p>Aber wollte es doch mal posten, evtl gibt es ja nen Trick oder doch einen Funktion die in der Liste die Key neu aktuallisiert, also eine Änderung der Sortierung ausführt.</p>
<p>Besten Dank schon mal für Anregungen, ich poste jetzt mal noch den Code:</p>
<p>// theClass - .h Datei</p>
<pre><code class="language-cpp">#ifndef __theClass__
#define __theClass__

// Header
#include &lt;wx/wx.h&gt;

class theClass
{
protected:
	wxString inhalt;
	const wxString* sort;

public:
	// ctor
	theClass();
	theClass(const wxString&amp; newInhalt);

	// dtor
	~theClass();

	// Get Inhalt
	wxString getInhalt() const;

	// Zeiger auf Sort Get()
	const wxString* GetSortPointer() const;

	// SortSet
	void SortSet(const wxString* newSort);

};
#endif // __theClass__
</code></pre>
<p>// theClass - .cpp Datei</p>
<pre><code class="language-cpp">// eigener Header
#include &quot;theClass.h&quot;

// Header aus Header
#include &lt;wx/wx.h&gt;

// ctor
theClass::theClass()
:inhalt(wxEmptyString)
,sort(0)
{
}
theClass::theClass( const wxString&amp; newInhalt)
:inhalt(newInhalt)
,sort(0)
{
}

// dtor
theClass::~theClass()
{
}

// Get Inhalt
wxString theClass::getInhalt() const
{
	return inhalt;
}

// Zeiger auf Sort Get()
const wxString* theClass::GetSortPointer() const
{
	return sort;
}

// SortSet
void theClass::SortSet(const wxString* newSort)
{
	sort = newSort;
}
</code></pre>
<p>// basic_frame - .cpp</p>
<pre><code class="language-cpp">// eigener header
#include &quot;basic_frame.h&quot;

// Header aus Header
#include &lt;wx/wx.h&gt;
#include &lt;wx/frame.h&gt;

// weitere Header
#include &lt;map&gt;
#include &quot;theClass.h&quot;

typedef std::map&lt;wxString, theClass&gt; mapStore;

BasicFrame::BasicFrame(const wxString &amp;title, const int &amp;xpos, const int &amp;ypos, const int &amp;width, const int &amp;hight)
:wxFrame( (wxFrame *)0, -1, title, wxPoint(xpos,ypos), wxSize(width,hight) )
{
	panel = new wxPanel(this);

	mapStore t;

	// Fünf Objecte
	theClass obj1(_T(&quot;Text of 1-A&quot;));
	theClass obj2(_T(&quot;Text of 2-B&quot;));
	theClass obj3(_T(&quot;Text of 3-C&quot;));
	theClass obj4(_T(&quot;Text of 4-D&quot;));
	theClass obj5(_T(&quot;Text of 5-E&quot;));

	// In die Liste
	t[_T(&quot;B&quot;)] = obj1;
	t[_T(&quot;C&quot;)] = obj2;
	t[_T(&quot;D&quot;)] = obj3;
	t[_T(&quot;E&quot;)] = obj4;
	t[_T(&quot;F&quot;)] = obj5;

	// Zeiger setzen
	for (mapStore::iterator it = t.begin(); it!=t.end(); it++)
	{
		it-&gt;second.SortSet(&amp;it-&gt;first);
	}

	// Element 1 Holen
	mapStore::iterator it = t.begin();

	// const abholen
	const wxString* b = it-&gt;second.GetSortPointer();

	// const wegcaste
	wxString* b1 = const_cast&lt;wxString*&gt;(b);

	// X an B zuweisen
	*b1 = _T(&quot;X&quot;);

	// &lt;--- hier müsste ich bei der map einen refresh ausführen // falls es sowas gibt

	//Liste neu sortieren
	it = t.find(_T(&quot;X&quot;));

	if (it != t.end())
	{
		wxMessageBox(it-&gt;second.getInhalt());
	}
	else
	{
		wxMessageBox(_T(&quot;Not Found&quot;));
	}

	bool allDone = true;
	allDone;
}

BasicFrame::~BasicFrame()
{
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2022611</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2022611</guid><dc:creator><![CDATA[Ollow_AM]]></dc:creator><pubDate>Fri, 18 Feb 2011 08:48:06 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu einer map on Fri, 18 Feb 2011 08:56:46 GMT]]></title><description><![CDATA[<p>Du willst keine std::map, sondern ein std::set. Dabei ist der Wert gleich dem Schlüssel. Ein Update läuft dann so: Alten werden holen -&gt; Alten Wert aus set löschen -&gt; Alten Wert ändern -&gt; geänderten Wert wieder ins set packen.<br />
Was soll die Sache mit dem <code>const_cast</code> ?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2022616</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2022616</guid><dc:creator><![CDATA[Tachyon]]></dc:creator><pubDate>Fri, 18 Feb 2011 08:56:46 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu einer map on Fri, 18 Feb 2011 09:31:50 GMT]]></title><description><![CDATA[<p>Hallo, ich hole mir ja in</p>
<pre><code class="language-cpp">// const abholen
const wxString* b = it-&gt;second.GetSortPointer();
</code></pre>
<p>einen Zeiger auf den (wxString) Key ab. Um diesen Key zu ändern muss ich ja const wegcasten.</p>
<blockquote>
<p>Alten Wert holen -&gt; Alten Wert aus set löschen -&gt; Alten Wert ändern -&gt; geänderten Wert wieder ins set packen.</p>
</blockquote>
<p>Hmm, eben das wollte ich umgehen. Indem ich den Key-Wert direkt ausändere und anschließend einen 'Refresh' der Liste starte in dem er quasi neu ordnet.</p>
<p>Gruß</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2022626</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2022626</guid><dc:creator><![CDATA[Ollow_AM]]></dc:creator><pubDate>Fri, 18 Feb 2011 09:31:50 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu einer map on Fri, 18 Feb 2011 09:35:41 GMT]]></title><description><![CDATA[<p>Ollow_AM schrieb:</p>
<blockquote>
<p>Hmm, eben das wollte ich umgehen. Indem ich den Key-Wert direkt ausändere und anschließend einen 'Refresh' der Liste starte in dem er quasi neu ordnet.</p>
</blockquote>
<p>Das geht eben nicht mit der normalen map. Wenn du den Key ändern könntest wäre die map ja zwischenzeitlich in einem ungeordneten Zustand. Das soll vermieden werden.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2022628</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2022628</guid><dc:creator><![CDATA[Braunstein]]></dc:creator><pubDate>Fri, 18 Feb 2011 09:35:41 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu einer map on Fri, 18 Feb 2011 09:39:10 GMT]]></title><description><![CDATA[<p>Jap das ist genau das was ich vermutet habe. Aber evtl hätte es ja doch einen Kniff gegeben der es mir erlaubt der map quasi zu sagen, 'ordne dich neu'.</p>
<p>Vielen Dank und fröhliches proggen....</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2022630</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2022630</guid><dc:creator><![CDATA[Ollow_AM]]></dc:creator><pubDate>Fri, 18 Feb 2011 09:39:10 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu einer map on Fri, 18 Feb 2011 09:40:56 GMT]]></title><description><![CDATA[<p>Du kannst dir ja deine eigene map schreiben. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2022631</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2022631</guid><dc:creator><![CDATA[Braunstein]]></dc:creator><pubDate>Fri, 18 Feb 2011 09:40:56 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu einer map on Fri, 18 Feb 2011 10:36:49 GMT]]></title><description><![CDATA[<p>Ollow_AM schrieb:</p>
<blockquote>
<p>Jap das ist genau das was ich vermutet habe. Aber evtl hätte es ja doch einen Kniff gegeben der es mir erlaubt der map quasi zu sagen, 'ordne dich neu'.</p>
<p>Vielen Dank und fröhliches proggen....</p>
</blockquote>
<p>Schreib Dir einfach eine freie Funktion, welche das für Dich macht, irgendwie so: <code>void reorder(std::set&lt;theClass&gt; &amp; container, wxString const &amp; oldKey, wxString const &amp; newKey)</code> . Da drin machst Du dann das tauschen von neuem und alten Wert. Eine <code>reorder</code> -Funktion von <code>std::set/std::map</code> würde es auch nicht anders machen können.</p>
<p>Ollow_AM schrieb:</p>
<blockquote>
<p>[...]</p>
<pre><code class="language-cpp">// const abholen
const wxString* b = it-&gt;second.GetSortPointer();
</code></pre>
<p>einen Zeiger auf den (wxString) Key ab. Um diesen Key zu ändern muss ich ja const wegcasten.<br />
[...]</p>
</blockquote>
<p>Dann mache doch <code>b</code> gar nicht erst const. Wenn der Rückgabewert von <code>GetSortPointer()</code> schon <code>const</code> -qualifiziert ist, dann ist es eh extrem unsauber.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2022653</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2022653</guid><dc:creator><![CDATA[Tachyon]]></dc:creator><pubDate>Fri, 18 Feb 2011 10:36:49 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu einer map on Fri, 18 Feb 2011 12:49:21 GMT]]></title><description><![CDATA[<p>Ollow_AM schrieb:</p>
<blockquote>
<p>Hallo, ich hole mir ja in</p>
<pre><code class="language-cpp">// const abholen
const wxString* b = it-&gt;second.GetSortPointer();
</code></pre>
<p>einen Zeiger auf den (wxString) Key ab. Um diesen Key zu ändern muss ich ja const wegcasten.</p>
<blockquote>
<p>Alten Wert holen -&gt; Alten Wert aus set löschen -&gt; Alten Wert ändern -&gt; geänderten Wert wieder ins set packen.</p>
</blockquote>
<p>Hmm, eben das wollte ich umgehen. Indem ich den Key-Wert direkt ausändere und anschließend einen 'Refresh' der Liste starte in dem er quasi neu ordnet.</p>
<p>Gruß</p>
</blockquote>
<p>Das neu sortieren ist definitiv langsamer als die paar Schritte, auch wenn du eine Zeile mehr schreiben musst.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2022753</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2022753</guid><dc:creator><![CDATA[Eisflamme]]></dc:creator><pubDate>Fri, 18 Feb 2011 12:49:21 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu einer map on Fri, 18 Feb 2011 13:32:02 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/22559">@Eisflamme</a> -</p>
<p>Ja, hmm denke mal weil er durch den Schlüssel direkt auf die Position zugreift diese löscht und dann wenn er das neue Object reinschiebt nur bis zu der Position durchgehen muss wo das neue Element eingefügt wird.</p>
<p>Und bei einem 'Refresh' müsste er vermutlich die gesamte Liste durchgehen, und damit eigentliches jedes Element 'anfassen'.</p>
<p>Thx...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2022785</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2022785</guid><dc:creator><![CDATA[Ollow_AM]]></dc:creator><pubDate>Fri, 18 Feb 2011 13:32:02 GMT</pubDate></item></channel></rss>