return result;
}
+unsigned int Analog::unitsize() const
+{
+ return _structure->encoding->unitsize;
+}
+
+bool Analog::is_signed() const
+{
+ return _structure->encoding->is_signed;
+}
+
+bool Analog::is_float() const
+{
+ return _structure->encoding->is_float;
+}
+
+bool Analog::is_bigendian() const
+{
+ return _structure->encoding->is_bigendian;
+}
+
+int Analog::digits() const
+{
+ return _structure->encoding->digits;
+}
+
+bool Analog::is_digits_decimal() const
+{
+ return _structure->encoding->is_digits_decimal;
+}
+
+shared_ptr<Rational> Analog::scale()
+{
+ unique_ptr<Rational> scale;
+ scale.reset(new Rational(&(_structure->encoding->scale)));
+
+ if (scale)
+ return scale->share_owned_by(shared_from_this());
+ else
+ throw Error(SR_ERR_NA);
+}
+
+shared_ptr<Rational> Analog::offset()
+{
+ unique_ptr<Rational> offset;
+ offset.reset(new Rational(&(_structure->encoding->offset)));
+
+ if (offset)
+ return offset->share_owned_by(shared_from_this());
+ else
+ throw Error(SR_ERR_NA);
+}
+
const Quantity *Analog::mq() const
{
return Quantity::get(_structure->meaning->mq);
return QuantityFlag::flags_from_mask(_structure->meaning->mqflags);
}
+Rational::Rational(const struct sr_rational *structure) :
+ _structure(structure)
+{
+}
+
+Rational::~Rational()
+{
+}
+
+shared_ptr<Rational> Rational::share_owned_by(shared_ptr<Analog> _parent)
+{
+ return static_pointer_cast<Rational>(
+ ParentOwned::share_owned_by(_parent));
+}
+
+int64_t Rational::numerator() const
+{
+ return _structure->p;
+}
+
+uint64_t Rational::denominator() const
+{
+ return _structure->q;
+}
+
+float Rational::value() const
+{
+ return (float)(_structure->p) / (float)(_structure->q);
+}
+
InputFormat::InputFormat(const struct sr_input_module *structure) :
_structure(structure)
{
class SR_API Quantity;
class SR_API Unit;
class SR_API QuantityFlag;
+class SR_API Rational;
class SR_API Input;
class SR_API InputDevice;
class SR_API Output;
unsigned int num_samples() const;
/** Channels for which this packet contains data. */
vector<shared_ptr<Channel> > channels();
+ /** Size of a single sample in bytes. */
+ unsigned int unitsize() const;
+ /** Samples use a signed data type. */
+ bool is_signed() const;
+ /** Samples use float. */
+ bool is_float() const;
+ /** Samples are stored in big-endian order. */
+ bool is_bigendian() const;
+ /**
+ * Number of significant digits after the decimal point if positive,
+ * or number of non-significant digits before the decimal point if negative
+ * (refers to the value we actually read on the wire).
+ */
+ int digits() const;
+ /** TBD */
+ bool is_digits_decimal() const;
+ /** TBD */
+ shared_ptr<Rational> scale();
+ /** TBD */
+ shared_ptr<Rational> offset();
/** Measured quantity of the samples in this packet. */
const Quantity *mq() const;
/** Unit of the samples in this packet. */
friend class Packet;
};
+/** Number represented by a numerator/denominator integer pair */
+class SR_API Rational :
+ public ParentOwned<Rational, Analog>
+{
+public:
+ /** Numerator, i.e. the dividend. */
+ int64_t numerator() const;
+ /** Denominator, i.e. the divider. */
+ uint64_t denominator() const;
+ /** Actual (lossy) value. */
+ float value() const;
+private:
+ explicit Rational(const struct sr_rational *structure);
+ ~Rational();
+ shared_ptr<Rational> share_owned_by(shared_ptr<Analog> parent);
+
+ const struct sr_rational *_structure;
+
+ friend class Analog;
+ friend struct std::default_delete<Rational>;
+};
+
/** An input format supported by the library */
class SR_API InputFormat :
public ParentOwned<InputFormat, Context>