OpenSTA/include/sta/Units.hh

105 lines
3.5 KiB
C++
Raw Normal View History

2018-09-28 17:54:21 +02:00
// OpenSTA, Static Timing Analyzer
// Copyright (c) 2025, Parallax Software, Inc.
2018-09-28 17:54:21 +02:00
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2018-09-28 17:54:21 +02:00
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//
// The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software.
//
// Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
//
// This notice may not be removed or altered from any source distribution.
2018-09-28 17:54:21 +02:00
2020-02-16 01:13:16 +01:00
#pragma once
2018-09-28 17:54:21 +02:00
#include <string>
2018-09-28 17:54:21 +02:00
namespace sta {
class Unit
{
public:
2020-06-24 02:11:48 +02:00
Unit(const char *suffix);
2018-09-28 17:54:21 +02:00
Unit(float scale,
const char *suffix,
int digits);
// Convert from sta units to user interface units.
double staToUser(double value);
// Convert from user interface units to sta units.
double userToSta(double value);
2019-11-11 21:03:38 +01:00
void operator=(const Unit &unit);
2018-09-28 17:54:21 +02:00
float scale() const { return scale_; }
void setScale(float scale);
const char *scaleAbbreviation() const;
const char *suffix() const { return suffix_.c_str(); }
// scale abbreviation + suffix
const char *scaledSuffix() const { return scaled_suffix_.c_str(); }
2018-09-28 17:54:21 +02:00
void setSuffix(const char *suffix);
int digits() const { return digits_; }
void setDigits(int digits);
2020-06-24 02:11:48 +02:00
// Does not include suffix.
2018-11-26 18:15:52 +01:00
int width() const;
2018-09-28 17:54:21 +02:00
const char *asString(float value) const;
const char *asString(double value) const;
const char *asString(float value,
int digits) const;
private:
void setScaledSuffix();
2018-09-28 17:54:21 +02:00
float scale_; // multiplier from user units to internal units
std::string suffix_; // print suffix
std::string scaled_suffix_;
2018-09-28 17:54:21 +02:00
int digits_; // print digits (after decimal pt)
};
// User interface units.
// Sta internal units are always seconds, farads, volts, amps.
class Units
{
public:
2020-06-24 02:11:48 +02:00
Units();
2018-09-28 17:54:21 +02:00
Unit *find(const char *unit_name);
2019-11-11 21:03:38 +01:00
void operator=(const Units &units);
2018-09-28 17:54:21 +02:00
Unit *timeUnit() { return &time_unit_; }
const Unit *timeUnit() const { return &time_unit_; }
Unit *capacitanceUnit() { return &capacitance_unit_; }
const Unit *capacitanceUnit() const { return &capacitance_unit_; }
Unit *voltageUnit() { return &voltage_unit_; }
const Unit *voltageUnit() const { return &voltage_unit_; }
Unit *resistanceUnit() { return &resistance_unit_; }
const Unit *resistanceUnit() const { return &resistance_unit_; }
Unit *currentUnit() { return &current_unit_; }
const Unit *currentUnit() const { return &current_unit_; }
Unit *powerUnit() { return &power_unit_; }
const Unit *powerUnit() const { return &power_unit_; }
Unit *distanceUnit() { return &distance_unit_; }
const Unit *distanceUnit() const { return &distance_unit_; }
Unit *scalarUnit() { return &scalar_unit_; }
const Unit *scalarUnit() const { return &scalar_unit_; }
private:
Unit time_unit_;
Unit resistance_unit_;
2018-09-28 17:54:21 +02:00
Unit capacitance_unit_;
Unit voltage_unit_;
Unit current_unit_;
Unit power_unit_;
Unit distance_unit_;
Unit scalar_unit_;
};
} // namespace