Library of reusable VHDL components
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

128 lines
4.2 KiB

  1. --
  2. -- File Name: NamePkg.vhd
  3. -- Design Unit Name: NamePkg
  4. -- Revision: STANDARD VERSION
  5. --
  6. -- Maintainer: Jim Lewis email: jim@synthworks.com
  7. -- Contributor(s):
  8. -- Jim Lewis SynthWorks
  9. --
  10. --
  11. -- Package Defines
  12. -- Data structure for name.
  13. --
  14. -- Developed for:
  15. -- SynthWorks Design Inc.
  16. -- VHDL Training Classes
  17. -- 11898 SW 128th Ave. Tigard, Or 97223
  18. -- http://www.SynthWorks.com
  19. --
  20. -- Latest standard version available at:
  21. -- http://www.SynthWorks.com/downloads
  22. --
  23. -- Revision History:
  24. -- Date Version Description
  25. -- 06/2010: 0.1 Initial revision
  26. -- 07/2014: 2014.07 Moved specialization required by CoveragePkg to CoveragePkg
  27. -- Separated name handling from message handling to simplify naming
  28. -- 12/2014: 2014.07a Removed initialized pointers which can lead to memory leaks.
  29. -- 05/2015 2015.06 Added input to Get to return when not initialized
  30. --
  31. --
  32. -- Copyright (c) 2010 - 2015 by SynthWorks Design Inc. All rights reserved.
  33. --
  34. -- Verbatim copies of this source file may be used and
  35. -- distributed without restriction.
  36. --
  37. -- This source file is free software; you can redistribute it
  38. -- and/or modify it under the terms of the ARTISTIC License
  39. -- as published by The Perl Foundation; either version 2.0 of
  40. -- the License, or (at your option) any later version.
  41. --
  42. -- This source is distributed in the hope that it will be
  43. -- useful, but WITHOUT ANY WARRANTY; without even the implied
  44. -- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  45. -- PURPOSE. See the Artistic License for details.
  46. --
  47. -- You should have received a copy of the license with this source.
  48. -- If not download it from,
  49. -- http://www.perlfoundation.org/artistic_license_2_0
  50. --
  51. use std.textio.all ;
  52. package NamePkg is
  53. type NamePType is protected
  54. procedure Set (NameIn : String) ;
  55. impure function Get (DefaultName : string := "") return string ;
  56. impure function GetOpt return string ;
  57. impure function IsSet return boolean ;
  58. procedure Clear ; -- clear name
  59. procedure Deallocate ; -- effectively alias to clear name
  60. end protected NamePType ;
  61. end package NamePkg ;
  62. --- ///////////////////////////////////////////////////////////////////////////
  63. --- ///////////////////////////////////////////////////////////////////////////
  64. --- ///////////////////////////////////////////////////////////////////////////
  65. package body NamePkg is
  66. type NamePType is protected body
  67. variable NamePtr : line ;
  68. ------------------------------------------------------------
  69. procedure Set (NameIn : String) is
  70. ------------------------------------------------------------
  71. begin
  72. deallocate(NamePtr) ;
  73. NamePtr := new string'(NameIn) ;
  74. end procedure Set ;
  75. ------------------------------------------------------------
  76. impure function Get (DefaultName : string := "") return string is
  77. ------------------------------------------------------------
  78. begin
  79. if NamePtr = NULL then
  80. return DefaultName ;
  81. else
  82. return NamePtr.all ;
  83. end if ;
  84. end function Get ;
  85. ------------------------------------------------------------
  86. impure function GetOpt return string is
  87. ------------------------------------------------------------
  88. begin
  89. if NamePtr = NULL then
  90. return NUL & "" ;
  91. else
  92. return NamePtr.all ;
  93. end if ;
  94. end function GetOpt ;
  95. ------------------------------------------------------------
  96. impure function IsSet return boolean is
  97. ------------------------------------------------------------
  98. begin
  99. return NamePtr /= NULL ;
  100. end function IsSet ;
  101. ------------------------------------------------------------
  102. procedure Clear is -- clear name
  103. ------------------------------------------------------------
  104. begin
  105. deallocate(NamePtr) ;
  106. end procedure Clear ;
  107. ------------------------------------------------------------
  108. procedure Deallocate is -- clear name
  109. ------------------------------------------------------------
  110. begin
  111. Clear ;
  112. end procedure Deallocate ;
  113. end protected body NamePType ;
  114. end package body NamePkg ;