UnitPrefix.h

// UnitPrefix.h
//
// Author David Barrett-Lennard
// (C)opyright Cedanet Pty Ltd 2012

#pragma once
#ifndef Ceda_cxUtils_UnitPrefix_H
#define Ceda_cxUtils_UnitPrefix_H

#include "xostream.h"

namespace ceda
{

// Returns "p", "n", "u", "m", "", "k", "M", "G" or "T" depending on value.  This is a suitable 
// prefix to be used to display the value to a user (p = pico n = nano, u = micro, m = milli, 
// k = kilo, M = mega, G = giga, T = tera)
// 'value' is an in-out parameter and is divided by the unit prefix.
cxUtils_API ConstStringZ GetShortMetricPrefix(double& value);

cxUtils_API ConstStringZ GetLongMetricPrefix(double& value);

// Similar to GetMetricPrefix() except 
//      k = 1024, M = 1024^2, G=1024^3, T = 1024^4
cxUtils_API ConstStringZ GetShortBinaryPrefix(double& value);

cxUtils_API ConstStringZ GetLongBinaryPrefix(double& value);


cxUtils_API void WriteRate(xostream& os, double rate, bool bytesPerSec);

///////////////////////////////////////////////////////////////////////////////////////////////////
// AsBytes()

struct BytesValue
{
    BytesValue(int64 _x = 0) : x(_x) {}
    operator int64() const { return x; }
    int64 x;
};

cxUtils_API xostream& operator<<(xostream& os, BytesValue v);

inline BytesValue AsBytes(int64 x) { return BytesValue(x); }

///////////////////////////////////////////////////////////////////////////////////////////////////
// AsShortMetricUnitPrefixed()

struct ShortMetricUnitPrefixed
{
    ShortMetricUnitPrefixed(double _x = 0) : x(_x) {}
    operator double() const { return x; }
    double x;
};

cxUtils_API xostream& operator<<(xostream& os, ShortMetricUnitPrefixed v);

inline ShortMetricUnitPrefixed AsShortMetricUnitPrefixed(double x) { return ShortMetricUnitPrefixed(x); }

///////////////////////////////////////////////////////////////////////////////////////////////////
// AsLongMetricUnitPrefixed()

struct LongMetricUnitPrefixed
{
    LongMetricUnitPrefixed(double _x = 0) : x(_x) {}
    operator double() const { return x; }
    double x;
};

cxUtils_API xostream& operator<<(xostream& os, LongMetricUnitPrefixed v);

inline LongMetricUnitPrefixed AsLongMetricUnitPrefixed(double x) { return LongMetricUnitPrefixed(x); }

///////////////////////////////////////////////////////////////////////////////////////////////////
// AsShortBinaryUnitPrefixed()

struct ShortBinaryUnitPrefixed
{
    ShortBinaryUnitPrefixed(double _x = 0) : x(_x) {}
    operator double() const { return x; }
    double x;
};

cxUtils_API xostream& operator<<(xostream& os, ShortBinaryUnitPrefixed v);

inline ShortBinaryUnitPrefixed AsShortBinaryUnitPrefixed(int32 x) { return ShortBinaryUnitPrefixed( (double) x); }
inline ShortBinaryUnitPrefixed AsShortBinaryUnitPrefixed(int64 x) { return ShortBinaryUnitPrefixed( (double) x); }
inline ShortBinaryUnitPrefixed AsShortBinaryUnitPrefixed(double x) { return ShortBinaryUnitPrefixed(x); }

///////////////////////////////////////////////////////////////////////////////////////////////////
// AsLongBinaryUnitPrefixed()

struct LongBinaryUnitPrefixed
{
    LongBinaryUnitPrefixed(double _x = 0) : x(_x) {}
    operator double() const { return x; }
    double x;
};

cxUtils_API xostream& operator<<(xostream& os, LongBinaryUnitPrefixed v);

inline LongBinaryUnitPrefixed AsLongBinaryUnitPrefixed(int32 x) { return LongBinaryUnitPrefixed( (double) x); }
inline LongBinaryUnitPrefixed AsLongBinaryUnitPrefixed(int64 x) { return LongBinaryUnitPrefixed( (double) x); }
inline LongBinaryUnitPrefixed AsLongBinaryUnitPrefixed(double x) { return LongBinaryUnitPrefixed(x); }

} // namespace ceda

#endif // include guard