<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>resources on autosys</title>
    <link>https://autosys.informatik.haw-hamburg.de/tags/resources/</link>
    <description>Recent content in resources on autosys</description>
    <generator>Source Themes Academic (https://sourcethemes.com/academic/)</generator>
    <language>en-us</language>
    <copyright>&amp;copy; {year}</copyright>
    <lastBuildDate>Mon, 13 Feb 2017 00:00:00 +0000</lastBuildDate>
    
	    <atom:link href="https://autosys.informatik.haw-hamburg.de/tags/resources/index.xml" rel="self" type="application/rss+xml" />
    
    
    <item>
      <title>Clone Factory</title>
      <link>https://autosys.informatik.haw-hamburg.de/codesamples/clone-factory/</link>
      <pubDate>Mon, 13 Feb 2017 00:00:00 +0000</pubDate>
      
      <guid>https://autosys.informatik.haw-hamburg.de/codesamples/clone-factory/</guid>
      <description>&lt;p&gt;A factory creates objects of a certain type. The factory takes an ID of some sort as an argument and creates the object which has been registered with the factory with the respective ID.&lt;/p&gt;
&lt;p&gt;This code sample shows one way to make  a factory. All objects are stored in an interal (intrusive) list inside the factory together with their ID. To create an object given its ID, the factory searches the list for the ID and calls the copy constructor of the object to create a new object of the same type.&lt;/p&gt;
&lt;p&gt;In the moment the new object comes into live, a so called virtual constructor call is made. The virtual constructor principle simply states, that there shall be a function like create() or construct() or init() which shall be called polymorphically. Real constructors may not be virtual, you see. This is because the object hasn´t been created yet and therefore no v-table exists.&lt;/p&gt;
&lt;p&gt;The virtual constructor call may be used e.g. for a deserialization call, in case your factory creates message objects. In this case the virtual constructor reads a byte stream and fill the freshly created object with data.&lt;/p&gt;
&lt;br /&gt;
&lt;script type=&#34;application/javascript&#34; src=&#34;https://gist.github.com/stephanpareigis/3cec02d5a09a20ddd9891fa87a896894.js&#34;&gt;&lt;/script&gt;

</description>
    </item>
    
    <item>
      <title>Memory Pool</title>
      <link>https://autosys.informatik.haw-hamburg.de/codesamples/memory-pool/</link>
      <pubDate>Mon, 13 Feb 2017 00:00:00 +0000</pubDate>
      
      <guid>https://autosys.informatik.haw-hamburg.de/codesamples/memory-pool/</guid>
      <description>&lt;p&gt;The memory pool is really fast in allocating and deallocating memory (O(1)). For real-time systems this is the right choice. It works by preallocating a pool of memory blocks. These memory blocks must all have the same size. So this is the downside to live with: This memory pool will only provide memory blocks of a certain size. If you need another size: Simply make another memory pool with that other size. There is also another issue: Memory hogging. Since the memory pools work on preallocated memory, they will never give it back to the operating system.&lt;/p&gt;
&lt;p&gt;This source code example shows how the memory pool works. One class is to overwrite new and delete. The other class is to implement the fairly simple memory pool algorithm. Essentially a free stack is used to remember the free memory blocks so that they can be immediately offered to the user upon his new call. A delete will simply put the memory block back to the free stack.&lt;/p&gt;
&lt;br/&gt;
&lt;script type=&#34;application/javascript&#34; src=&#34;https://gist.github.com/stephanpareigis/af162cb5f814623d6d92afa0c0c57ca9.js&#34;&gt;&lt;/script&gt;

</description>
    </item>
    
    <item>
      <title>Signal ID to function call in state machines</title>
      <link>https://autosys.informatik.haw-hamburg.de/codesamples/from-signal-id-to-function-call/</link>
      <pubDate>Mon, 13 Feb 2017 00:00:00 +0000</pubDate>
      
      <guid>https://autosys.informatik.haw-hamburg.de/codesamples/from-signal-id-to-function-call/</guid>
      <description>&lt;h1 id=&#34;mapping-signal-ids-to-function-calls&#34;&gt;Mapping Signal IDs to function calls&lt;/h1&gt;
&lt;p&gt;The state machine pattern assumes, that function calls are made by each incoming signal. But what if the signals exist only as a number or ID? How is the ID transformed into a function call? Of course, you could simply write a switch case, converting the integer ID into a function call. But  switch cases &amp;ldquo;smell&amp;rdquo; (look into Martin Fowlers book on Refactoring).&lt;/p&gt;
&lt;p&gt;This example uses the function &lt;code&gt;process(Signal s)&lt;/code&gt; (line 61, lines 76 and 77) to process the signal which is given as an ID.  Look at line 63 where the respective function is being called (omit lines 62 and 64 in your production code). It´s just one line of code: No switch case. How is this done?&lt;/p&gt;
&lt;p&gt;&lt;code&gt;funcArray&lt;/code&gt; is an &lt;code&gt;std::vector&lt;/code&gt; of member function pointers. The signal ID is simply the index of the respective function in the function pointer array.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;std::vector&lt;/code&gt; is initialized in line 67. Lambdas need to be used to store member functions in the function pointer array.&lt;/p&gt;
&lt;p&gt;The code also shows how to print the current state using the build-in tool typeinfo.&lt;/p&gt;
&lt;p&gt;The code below should compile using the old C++03.&lt;/p&gt;
&lt;script type=&#34;application/javascript&#34; src=&#34;https://gist.github.com/stephanpareigis/21e8ef1478990d5ad46481e13e6d92d8.js&#34;&gt;&lt;/script&gt;

&lt;h2 id=&#34;c03-source-code-example&#34;&gt;C++03 Source Code Example&lt;/h2&gt;
&lt;script type=&#34;application/javascript&#34; src=&#34;https://gist.github.com/stephanpareigis/72df7616bdfe5c67da28608446d04c3f.js&#34;&gt;&lt;/script&gt;

</description>
    </item>
    
    <item>
      <title>Thread Control</title>
      <link>https://autosys.informatik.haw-hamburg.de/codesamples/thread-control/</link>
      <pubDate>Mon, 13 Feb 2017 00:00:00 +0000</pubDate>
      
      <guid>https://autosys.informatik.haw-hamburg.de/codesamples/thread-control/</guid>
      <description>&lt;h1 id=&#34;how-to-stop-a-thread&#34;&gt;How to stop a thread.&lt;/h1&gt;
&lt;p&gt;It is a nice idea to create a functor (overload operator()) and pass a functor object to a thread. The operator()() (line 9) should generally contain a while loop (event loop)(line 10). To be able to stop the while loop from the outside, one can use a member variable of the functor, e.g. bool IsStopped or bool IsRunning (line 15). The loop would then look like this&lt;/p&gt;
&lt;p&gt;&lt;code&gt;while(IsRunning){...}&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Another thread (e.g. the main thread) could then set the flag to true (or false) (line 23) and this will end the while loop.&lt;/p&gt;
&lt;p&gt;In order to make this work, the functor object has to be passed as a reference to the thread (line 20).&lt;/p&gt;
&lt;p&gt;&lt;code&gt;thread(std::ref(thread01));&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;If you need more sophisticated communication between threads, you should use the buffer or channel which are described in separate posts.&lt;/p&gt;
&lt;br /&gt;
&lt;script type=&#34;application/javascript&#34; src=&#34;https://gist.github.com/stephanpareigis/09a26bc9e7b391bd6f29532c198f1b99.js&#34;&gt;&lt;/script&gt;

</description>
    </item>
    
  </channel>
</rss>
