<?xml version='1.0' encoding='UTF-8' standalone='no'?>
<doxygen xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="compound.xsd" version="1.8.20" xml:lang="en-US">
  <compounddef id="MetricManagerAdvanced_8cpp-example" kind="example">
    <compoundname>MetricManagerAdvanced.cpp</compoundname>
    <briefdescription>
    </briefdescription>
    <detaileddescription>
<para>A more advanced metric that updates the history of a metric. Usually this would be a metric from an external data source, e.g. e-mail or Facebook messages. <programlisting filename="MetricManagerAdvanced.cpp"><codeline><highlight class="preprocessor">#include<sp/>&lt;<ref refid="MetricManager_8h" kindref="compound">libusermetricsinput/MetricManager.h</ref>&gt;</highlight><highlight class="normal"></highlight></codeline>
<codeline><highlight class="normal"></highlight><highlight class="preprocessor">#include<sp/>&lt;QtCore/QCoreApplication&gt;</highlight><highlight class="normal"></highlight></codeline>
<codeline><highlight class="normal"></highlight></codeline>
<codeline><highlight class="normal"></highlight><highlight class="keyword">using<sp/>namespace<sp/></highlight><highlight class="normal"><ref refid="namespaceUserMetricsInput" kindref="compound">UserMetricsInput</ref>;</highlight></codeline>
<codeline><highlight class="normal"></highlight></codeline>
<codeline><highlight class="normal"></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/>main(</highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/>argc,<sp/></highlight><highlight class="keywordtype">char</highlight><highlight class="normal"><sp/>*argv[])<sp/>{</highlight></codeline>
<codeline><highlight class="normal"><sp/><sp/><sp/><sp/>QCoreApplication<sp/>application(argc,<sp/>argv);</highlight></codeline>
<codeline><highlight class="normal"></highlight></codeline>
<codeline><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>We<sp/>start<sp/>with<sp/>a<sp/>manager<sp/>object</highlight><highlight class="normal"></highlight></codeline>
<codeline><highlight class="normal"><sp/><sp/><sp/><sp/><ref refid="namespaceUserMetricsInput_1a2f7898162932dad95bccf206c795b1e7" kindref="member">MetricManagerPtr</ref><sp/>manager(<ref refid="classUserMetricsInput_1_1MetricManager_1a1634db867ec49218befc231f67c3e4b3" kindref="member">MetricManager::getInstance</ref>());</highlight></codeline>
<codeline><highlight class="normal"></highlight></codeline>
<codeline><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>You<sp/>can<sp/>hold<sp/>onto<sp/>this<sp/>shared<sp/>pointer<sp/>for<sp/>as<sp/>long<sp/>as<sp/>you<sp/>want</highlight><highlight class="normal"></highlight></codeline>
<codeline><highlight class="normal"><sp/><sp/><sp/><sp/><ref refid="namespaceUserMetricsInput_1af5d8d34e6e6ea8560855d005f8b8c118" kindref="member">MetricPtr</ref><sp/>metric(</highlight></codeline>
<codeline><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>manager-&gt;add(</highlight></codeline>
<codeline><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="classUserMetricsInput_1_1MetricParameters" kindref="compound">MetricParameters</ref>(</highlight><highlight class="stringliteral">&quot;twitter&quot;</highlight><highlight class="normal">).formatString(</highlight></codeline>
<codeline><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="stringliteral">&quot;&lt;b&gt;%1&lt;/b&gt;<sp/>tweets<sp/>received<sp/>today&quot;</highlight><highlight class="normal">).emptyDataString(</highlight></codeline>
<codeline><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="stringliteral">&quot;No<sp/>tweets<sp/>today&quot;</highlight><highlight class="normal">).textDomain(APP_ID)));</highlight></codeline>
<codeline><highlight class="normal"></highlight></codeline>
<codeline><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>The<sp/>update<sp/>is<sp/>sent<sp/>when<sp/>the<sp/>update<sp/>object<sp/>is<sp/>destroyed</highlight><highlight class="normal"></highlight></codeline>
<codeline><highlight class="normal"><sp/><sp/><sp/><sp/><ref refid="namespaceUserMetricsInput_1aada5f30a76fc143abd39a6090db8e122" kindref="member">MetricUpdatePtr</ref><sp/>update(metric-&gt;update());</highlight></codeline>
<codeline><highlight class="normal"></highlight></codeline>
<codeline><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Get<sp/>our<sp/>data<sp/>from<sp/>somewhere</highlight><highlight class="normal"></highlight></codeline>
<codeline><highlight class="normal"><sp/><sp/><sp/><sp/>TwitterService<sp/>twitterService;</highlight></codeline>
<codeline><highlight class="normal"></highlight></codeline>
<codeline><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>The<sp/>data<sp/>is<sp/>ordered<sp/>starting<sp/>from<sp/>today,<sp/>going<sp/>backwards<sp/>in<sp/>time</highlight><highlight class="normal"></highlight></codeline>
<codeline><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">for</highlight><highlight class="normal"><sp/>(</highlight><highlight class="keyword">const</highlight><highlight class="normal"><sp/>TwitterData<sp/>&amp;twitterData<sp/>:<sp/>twitterService.getTweetCounts())<sp/>{</highlight></codeline>
<codeline><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>update-&gt;addData(twitterData.toDouble());</highlight></codeline>
<codeline><highlight class="normal"><sp/><sp/><sp/><sp/>}</highlight></codeline>
<codeline><highlight class="normal"></highlight></codeline>
<codeline><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>0;</highlight></codeline>
<codeline><highlight class="normal">}</highlight></codeline>
</programlisting> </para>
    </detaileddescription>
  </compounddef>
</doxygen>
