Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to store a boost::quantity with possible different boost::dimension
    primarykey
    data
    text
    <p>I am using <code>boost::units</code> library to enforce physical consistency in a scientific project. I have read and tried several examples from boost documentation. I am able to create my dimensions, units and quantities. I did some calculus, it works very well. It is exactly what I expected, except that...</p> <p>In my project, I deal with time series which have several different units (temperature, concentration, density, etc.) based on six dimensions. In order to allow safe and easy units conversions, I would like to add a member to each channel class representing the dimensions and units of time series. And, data treatment (import, conversion, etc.) are user-driven, therefore dynamic.</p> <p>My problem is the following, because of the <code>boost::units</code> structure, quantities within an homogeneous system but with different dimensions have different types. Therefore you cannot directly declare a member such as:</p> <pre><code>boost::units::quantity channelUnits; </code></pre> <p>Compiler will claim you have to specify dimensions using template chevrons. But if you do so, you will not be able to store different type of quantities (say quantities with different dimensions).</p> <p>Then, I looked for <code>boost::units::quantity</code> declaration to find out if there is a base class that I can use in a polymorphic way. But I haven't found it, instead I discovered that <code>boost::units</code> heavily uses <em>Template Meta Programming</em> which is not an issue but does not exactly fit my dynamic needs since everything is resolved at compile-time not at run-time.</p> <p>After more reading, I tried to wrap different quantities in a <code>boost::variant</code> object (nice to meet it for the very first time).</p> <pre><code>typedef boost::variant&lt; boost::units::quantity&lt;dim1&gt;, ... &gt; channelUnitsType; channelUnitsType channelUnits; </code></pre> <p>I performed some tests and it seems to work. But I am not confident with <code>boost::variant</code> and the <em>visitor-pattern</em>.</p> <p>My questions are the following:</p> <ul> <li>Is there another - maybe best - way to have run-time type resolution?</li> <li>Is <code>dynamic_cast</code> one of them? Units conversion will not happen very often and only few data are in concern.</li> <li>If <code>boost::variant</code> is a suitable solution, what are its drawbacks?</li> </ul>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload