Coverage for hdl_registers/constant/string_constant.py: 100%
18 statements
« prev ^ index » next coverage.py v7.6.9, created at 2024-12-19 20:51 +0000
« prev ^ index » next coverage.py v7.6.9, created at 2024-12-19 20:51 +0000
1# --------------------------------------------------------------------------------------------------
2# Copyright (c) Lukas Vik. All rights reserved.
3#
4# This file is part of the hdl-registers project, an HDL register generator fast enough to run
5# in real time.
6# https://hdl-registers.com
7# https://github.com/hdl-registers/hdl-registers
8# --------------------------------------------------------------------------------------------------
10# Standard libraries
11from typing import Optional
13# Local folder libraries
14from .constant import Constant
17class StringConstant(Constant):
18 def __init__(self, name: str, value: str, description: Optional[str] = None):
19 """
20 Arguments:
21 name: The name of the constant.
22 value: The constant value.
23 description: Textual description for the constant.
24 """
25 self.name = name
26 self.description = "" if description is None else description
28 self._value = ""
29 # Assign self._value via setter
30 self.value = value
32 @property
33 def value(self) -> str:
34 """
35 Getter for value.
36 """
37 return self._value
39 @value.setter
40 def value(self, value: str) -> None:
41 """
42 Setter for value that performs sanity checks.
43 """
44 if not isinstance(value, str):
45 raise ValueError(
46 f'Constant "{self.name}" has invalid data type "{type(value)}". Value: "{value}".'
47 )
49 self._value = value
51 def __repr__(self) -> str:
52 return f"""{self.__class__.__name__}(\
53name={self.name},\
54value={self.value},\
55description={self.description},\
56)"""