Skip to content
/ sipp Public

SI++ header only library for SI units conversions

License

Notifications You must be signed in to change notification settings

vinnyspb/sipp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Linux/macOS Build Status Windows Build status codecov

SI++ library

Description

Inspired by std::chrono, header-only library providing compile-time conversions and type-safety between different unit metrics.

Name SI comes from International System of Units, though the library now includes other unites as well.

Library provides 2 basic template types: Distance and Speed.

Think about these as std::chrono::duration<> template. There are typedefs instantiating exact metric units (see below).

Dependencies

GCC 5+

or

Clang 3.8+

or

MS Visual Studio 2017+

Distance

Example

#include <sipp/sipp.hpp>

// use <sipp/sipp_fwd.hpp> for just forward declarations

// ...

using namespace sipp::literals;

auto distance_in_km = 100.0_km;
sipp::Feet distance_in_feet = distance_in_km;

std::cout << "Distance in kilometers: " << distance_in_km.count() << std::endl;
std::cout << "Distance in feet: " << distance_in_feet.count() << std::endl;

auto casted = sipp::distance_cast<sipp::Meters>(5 * distance_in_km);
std::cout << "Multiplied kilometers and cast to meters: " << casted.count() << std::endl;

Implemented unit metrics

  • sipp::Meters, literal _m
  • sipp::Kilometers, literal _km
  • sipp::Millimeters, literal _mm
  • sipp::Micrometers, literal _um
  • sipp::Nanometers, literal _nm
  • sipp::Feet, literal _ft
  • sipp::NauticalMiles, literal _NM
  • sipp::StatuteMiles, literal _mi

Speed

Example

#include <sipp/sipp.hpp>

// ...

using namespace sipp::literals;

auto speed_in_kmh = 100.0_km_h;
sipp::Knots speed_in_knots = speed_in_kmh;

std::cout << "Speed in km/h " << speed_in_kmh.count() << std::endl;
std::cout << "Speed in knots: " << speed_in_knots.count() << std::endl;

auto casted = sipp::speed_cast<sipp::FeetPerMinute>(speed_in_knots + 10_m_s);
std::cout << "100 km/h + 10 m/s casted to feet/min: " << casted.count() << std::endl;

Implemented unit metrics

  • sipp::KmPerHour, literal _km_h
  • sipp::MetersPerSecond, literal _m_s
  • sipp::FeetPerSecond, literal _ft_s
  • sipp::FeetPerMinute, literal _ft_min
  • sipp::Knots, literal _kts
  • sipp::MilesPerHour, literal _mph

Contribution

There are unit tests, which can be built with cmake. Requires googletest (which is in git submodule 3rdparty/googletest).

$ cd /path/to/sources
$ git submodule update --init --recursive
$ mkdir -p build
$ cd build
$ cmake -DCMAKE_BUILD_TYPE=Debug ../
$ make sipp_tests
$ ./sipp_tests

About

SI++ header only library for SI units conversions

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published