unit-template-library

Simple Header-only library to represent type-safety SI units.

https://github.com/adamek727/unit-template-library

Science Score: 44.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (13.6%) to scientific vocabulary
Last synced: 6 months ago · JSON representation ·

Repository

Simple Header-only library to represent type-safety SI units.

Basic Info
  • Host: GitHub
  • Owner: adamek727
  • License: mit
  • Language: C++
  • Default Branch: main
  • Size: 42 KB
Statistics
  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • Open Issues: 0
  • Releases: 0
Created almost 2 years ago · Last pushed almost 2 years ago
Metadata Files
Readme License Citation

README.md

Unit Template Library

Easy to use header-only library to represent type-safety SI units.

Authors and feedback

For technical feedback, bug reporting, feature proposition etc. please use the GitHub issue system. Opening issues allows all of us to participate on the solution, library related things are kept with its repository and other users may benefit from our communication as well.

  • Adam Ligocki ligocki.a@gmail.com

The library is successor of the Robotic Template Library.

Usage Example

Code example

```

include

// Definition and unit conversion auto a = Area(6543); std::cout << "Area: " << a.m2() << std::endl;

// Operations with predefined operators auto v = Velocity(30); // mps auto t = Time(5); auto d = v * t; std::cout << "Distance: " << d.m() << "m" << std::endl;

auto g = Acceleration(9.81); auto tt = Time(10); auto s = 0.5 * g * tt * tt; std::cout << "Free fall: " << s.m() << "m" << std::endl;

// Operations without predefined operators. auto m = Mass(1); auto &c = speedoflight_f; auto e = (m.raw() * c.raw() * c.raw()).type(); std::cout << "Energy: " << e.J() << "J" << std::endl;

// Precision selection auto unitf = Unit(MPI); auto unitd = Unit(MPI); std::cout << std::fixed << std::setprecision(18) << "float: " << unitf.value() << " double: " << unitd.value() << std::endl; ```

Add to Existing Project

git submodule add https://github.com/adamek727/Unit-Template-Library libs/utl/ git submodule init git submodule update --recursive

and in your CMakeLists.txt file add

include_directories(libs/utl/include/)

Now you are able to include UTL headers into you code.

Run Examples

To make just a brief overview and to make the examples work, clone this repo and run following commands. git clone https://github.com/adamek727/Unit-Template-Library cd Unit-Template-Library/ mkdir build cd build cmake .. -DENABLE_EXAMPLES=1 make -j4

Run Tests

To evaluate tests, run: git clone https://github.com/adamek727/Unit-Template-Library cd Unit-Template-Library/ mkdir build cd build cmake .. -DENABLE_TESTS=1 make -j4 ctest

Inspiration:

  • https://github.com/wardw/simpleunit/tree/master
  • https://github.com/mpusz/mp-units
  • https://docs.wpilib.org/en/stable/docs/software/basic-programming/cpp-units.html
  • https://www.youtube.com/watch?v=o0ck5eqpOLc

Reference

If you find this library useful, please mention it in the README of your project, or cite it.

License

MIT License

Copyright (c) 2024 Adam Ligocki

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Owner

  • Name: adam ligocki
  • Login: adamek727
  • Kind: user

Citation (CITATION.cff)

cff-version: 1.2.0
message: "If you use this software, please cite it as below."
authors:
  - family-names: Ligocki
    given-names: Adam
    orcid: https://orcid.org/0000-0002-6813-4318
title: "Unit Template Library"
version: 1.0.0
date-released: 2024-5-5

GitHub Events

Total
Last Year