<?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[property template]]></title><description><![CDATA[<p>hola leute</p>
<p>bastel grad an einem property template. bin aber nicht so recht zufrieden damit.<br />
erst mal bissl code</p>
<p>hmm, komm grad drauf, das der [C/C++] button unter dem 'Nachrichtentext' nicht funktioniert. bei euch auch so ? oder spinnt mein FireFox ?<br />
naja.</p>
<pre><code class="language-cpp">// property-header
template &lt;class Class, class T &gt;
class Property
{
	public:
		typedef T (Class::*cb_func)(const T&amp;);

		Property(Class *obj, cb_func func) : host(obj), callback(func) { }
		Property(Class *obj, cb_func func, const Property&lt;Class, T&gt; &amp;p) :
												  host(obj), callback(func), val(p.val) { }
		Property(Class *obj, cb_func func, const T &amp;v) : host(obj),
												  callback(func), val(v) { }
		~Property(void) { }

		operator const T&amp;(void) { return val; }
		const Property&lt;Class, T&gt;&amp; operator=(const T &amp;v)
		{
			val = (host-&gt;*callback)(v);
			return *this;
		}

		const Property&lt;Class, T&gt;&amp; operator=(const Property&lt;Class, T&gt; &amp;v)
		{
			val = (host-&gt;*callback)(v.val);
			return *this;
		}

		void SetCallback(cb_func t_func) { callback = t_func; }

	private:
		T val;
		Class *host;
		cb_func callback;
};

// ein test
__fastcall TFMain::TFMain(TComponent* Owner): TForm(Owner)
{
	Property&lt;TFMain, int&gt; x(this, &amp;TFMain::OnChangeValue); // (1)
	x = 45;
	ShowMessage((int)x);
	x = 55;
	ShowMessage((int)x);
	x.SetCallback(&amp;TFMain::OnChangingValue);
	x = x;
	ShowMessage((int)x);
}

int TFMain::OnChangeValue(const int &amp;x)
{
	return x &gt; 50 ? 50 : x;
}

int TFMain::OnChangingValue(const int &amp;x)
{
	return x &gt; 30 ? 30 : x;
}
</code></pre>
<p>erstmals gefaellt mir die zeile (1) nicht. kann man das vielleicht vereinfachen?<br />
bei</p>
<pre><code class="language-cpp">Property&lt;TFMain, int&gt; x(this, &amp;TFMain::OnChangeValue);
</code></pre>
<p>hab ich doch irgendwie 3 mal die selbe info drinnen.<br />
erstmals das der template-parameter 'Class' ein TFMain ist, dann das der erste parameter des konstruktors ein pointer drauf ist und das die uebergebene methode zu TFMain gehoert.<br />
fein waere es wenn mann vielleicht aehnliches wie folgendes machen koennte:</p>
<pre><code class="language-cpp">Property&lt;int&gt; x(this, &amp;OnChangeValue);
</code></pre>
<p>was haettet ihr fuer aenderungsvorschlaege, favon abgesehen, das es schon fertige property klassen im netz gibt. soll fuer mich eher einen lerneffekt haben.</p>
<p>Meep Meep</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/168206/property-template</link><generator>RSS for Node</generator><lastBuildDate>Wed, 16 Sep 2026 09:05:22 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/168206.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 19 Dec 2006 16:10:38 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to property template on Tue, 19 Dec 2006 16:10:38 GMT]]></title><description><![CDATA[<p>hola leute</p>
<p>bastel grad an einem property template. bin aber nicht so recht zufrieden damit.<br />
erst mal bissl code</p>
<p>hmm, komm grad drauf, das der [C/C++] button unter dem 'Nachrichtentext' nicht funktioniert. bei euch auch so ? oder spinnt mein FireFox ?<br />
naja.</p>
<pre><code class="language-cpp">// property-header
template &lt;class Class, class T &gt;
class Property
{
	public:
		typedef T (Class::*cb_func)(const T&amp;);

		Property(Class *obj, cb_func func) : host(obj), callback(func) { }
		Property(Class *obj, cb_func func, const Property&lt;Class, T&gt; &amp;p) :
												  host(obj), callback(func), val(p.val) { }
		Property(Class *obj, cb_func func, const T &amp;v) : host(obj),
												  callback(func), val(v) { }
		~Property(void) { }

		operator const T&amp;(void) { return val; }
		const Property&lt;Class, T&gt;&amp; operator=(const T &amp;v)
		{
			val = (host-&gt;*callback)(v);
			return *this;
		}

		const Property&lt;Class, T&gt;&amp; operator=(const Property&lt;Class, T&gt; &amp;v)
		{
			val = (host-&gt;*callback)(v.val);
			return *this;
		}

		void SetCallback(cb_func t_func) { callback = t_func; }

	private:
		T val;
		Class *host;
		cb_func callback;
};

// ein test
__fastcall TFMain::TFMain(TComponent* Owner): TForm(Owner)
{
	Property&lt;TFMain, int&gt; x(this, &amp;TFMain::OnChangeValue); // (1)
	x = 45;
	ShowMessage((int)x);
	x = 55;
	ShowMessage((int)x);
	x.SetCallback(&amp;TFMain::OnChangingValue);
	x = x;
	ShowMessage((int)x);
}

int TFMain::OnChangeValue(const int &amp;x)
{
	return x &gt; 50 ? 50 : x;
}

int TFMain::OnChangingValue(const int &amp;x)
{
	return x &gt; 30 ? 30 : x;
}
</code></pre>
<p>erstmals gefaellt mir die zeile (1) nicht. kann man das vielleicht vereinfachen?<br />
bei</p>
<pre><code class="language-cpp">Property&lt;TFMain, int&gt; x(this, &amp;TFMain::OnChangeValue);
</code></pre>
<p>hab ich doch irgendwie 3 mal die selbe info drinnen.<br />
erstmals das der template-parameter 'Class' ein TFMain ist, dann das der erste parameter des konstruktors ein pointer drauf ist und das die uebergebene methode zu TFMain gehoert.<br />
fein waere es wenn mann vielleicht aehnliches wie folgendes machen koennte:</p>
<pre><code class="language-cpp">Property&lt;int&gt; x(this, &amp;OnChangeValue);
</code></pre>
<p>was haettet ihr fuer aenderungsvorschlaege, favon abgesehen, das es schon fertige property klassen im netz gibt. soll fuer mich eher einen lerneffekt haben.</p>
<p>Meep Meep</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1194926</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1194926</guid><dc:creator><![CDATA[Meep Meep]]></dc:creator><pubDate>Tue, 19 Dec 2006 16:10:38 GMT</pubDate></item><item><title><![CDATA[Reply to property template on Tue, 19 Dec 2006 17:43:06 GMT]]></title><description><![CDATA[<p>Meep Meep schrieb:</p>
<blockquote>
<pre><code class="language-cpp">Property&lt;int&gt; x(this, &amp;OnChangeValue);
</code></pre>
</blockquote>
<p>Nö, so wie es bereits ist, ist es korrekt! Hier hast du zu wenig Informationen.</p>
<p>grüße</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1194991</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1194991</guid><dc:creator><![CDATA[David_pb]]></dc:creator><pubDate>Tue, 19 Dec 2006 17:43:06 GMT</pubDate></item><item><title><![CDATA[Reply to property template on Wed, 20 Dec 2006 00:41:04 GMT]]></title><description><![CDATA[<p>Du könntest boost::function&lt;T(T const&amp;)&gt; anstelle eines Member Function Pointers verwende, dann könntest du es so schreiben:</p>
<pre><code class="language-cpp">Property&lt;int&gt; x(boost::bind(&amp;TFMain::OnChangeValue, this, _1));
</code></pre>
<p>Der grösste Vorteil dabei ist dass es immer ein Property&lt;int&gt; ist, egal was für eine Callback Funktion drangebunden ist. So wie du es machst wären Property&lt;Foo, int&gt; und Property&lt;Bar, int&gt; 2 komplett unverwandte Klassen die auch nicht interagieren können bzw. auch nicht gegeneinander ausgetauscht werden können (es sei denn natürlich du schreibst extra Code dafür).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1195172</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1195172</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Wed, 20 Dec 2006 00:41:04 GMT</pubDate></item><item><title><![CDATA[Reply to property template on Wed, 20 Dec 2006 07:08:24 GMT]]></title><description><![CDATA[<p>hola hustbaer</p>
<p>eine abhaengigkeit zu boost wollte ich ansich nicht schaffen. hab innerlich eine abneigung gegen boost. woher die kommt, weiß ich bis heute noch nicht. aber die funktionalitaet deiner beschreibung klingt recht interessant. werde mir mal den source angucken, vielleicht kann ich da was fuer meine klasse verwenden.<br />
schließlich</p>
<p>Meep Meep schrieb:</p>
<blockquote>
<p>soll fuer mich eher einen lerneffekt haben.</p>
</blockquote>
<p>Meep Meep</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1195201</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1195201</guid><dc:creator><![CDATA[Meep Meep]]></dc:creator><pubDate>Wed, 20 Dec 2006 07:08:24 GMT</pubDate></item><item><title><![CDATA[Reply to property template on Wed, 20 Dec 2006 13:05:05 GMT]]></title><description><![CDATA[<p>Meep Meep schrieb:</p>
<blockquote>
<p>...</p>
<pre><code class="language-cpp">...
		const Property&lt;Class, T&gt;&amp; operator=(const T &amp;v)
		{
			val = (host-&gt;*callback)(v);
			return *this;
		}

		const Property&lt;Class, T&gt;&amp; operator=(const Property&lt;Class, T&gt; &amp;v)
		{
			val = (host-&gt;*callback)(v.val);
			return *this;
		}
...
</code></pre>
</blockquote>
<p>Vielleicht ist das ja üblich, aber ich finde diese Semantik etwas verwirrend.<br />
Dass ein &quot;=&quot; einen Funktionsaufruf des gebundenen Objekts durchführt, hätte ich nicht erwartet.<br />
... OK, Du bindest in Deinem Beispiel eine Funktion &quot;OnChangeValue&quot; daran ... aber auch eine Funktion namens &quot;onExternalDeviceInput&quot; würde durch den operator=() ausgeführt werden.</p>
<p>Außerdem hätte ich mir unter &quot;Property&quot; überhaupt keinen &quot;Callback-Funktionstreiber&quot; vorgestellt....</p>
<p>Kann gut sein, dass ich da falsch liege, aber das ist nunmal mein Eindruck.</p>
<p>Gruß,</p>
<p>Simon2.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1195373</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1195373</guid><dc:creator><![CDATA[Simon2]]></dc:creator><pubDate>Wed, 20 Dec 2006 13:05:05 GMT</pubDate></item><item><title><![CDATA[Reply to property template on Wed, 20 Dec 2006 13:15:17 GMT]]></title><description><![CDATA[<p>Das könnte auch an einer unpassenden Namensgebung liegen <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /> (bei einer Property würde ich erwarten, daß op= die zugeordnete Set()-Methode des Mutter-Elements aufruft, da passt der Name 'callback' nicht so richtig)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1195378</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1195378</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Wed, 20 Dec 2006 13:15:17 GMT</pubDate></item></channel></rss>