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
52use std.textio.all ;
53
54package NamePkg is
55
56  type NamePType is protected
57    procedure Set (NameIn : String) ;
58    impure function Get (DefaultName : string := "") return string ;
59    impure function GetOpt return string ;
60    impure function IsSet return boolean ;
61    procedure Clear ; -- clear name
62    procedure Deallocate ; -- effectively alias to clear name
63  end protected NamePType ;
64
65end package NamePkg ;
66
67--- ///////////////////////////////////////////////////////////////////////////
68--- ///////////////////////////////////////////////////////////////////////////
69--- ///////////////////////////////////////////////////////////////////////////
70
71package body NamePkg is
72  type NamePType is protected body
73
74    variable NamePtr   : line ;
75
76    ------------------------------------------------------------
77    procedure Set (NameIn : String) is
78    ------------------------------------------------------------
79    begin
80      deallocate(NamePtr) ;
81      NamePtr := new string'(NameIn) ;
82    end procedure Set ;
83
84    ------------------------------------------------------------
85    impure function Get (DefaultName : string := "") return string is
86    ------------------------------------------------------------
87    begin
88      if NamePtr = NULL then
89        return DefaultName ;
90      else
91        return NamePtr.all ;
92      end if ;
93    end function Get ;
94
95    ------------------------------------------------------------
96    impure function GetOpt return string is
97    ------------------------------------------------------------
98    begin
99      if NamePtr = NULL then
100        return NUL & "" ;
101      else
102        return NamePtr.all ;
103      end if ;
104    end function GetOpt ;
105
106    ------------------------------------------------------------
107    impure function IsSet return boolean is
108    ------------------------------------------------------------
109    begin
110      return NamePtr /= NULL ;
111    end function IsSet ;
112
113    ------------------------------------------------------------
114    procedure Clear is  -- clear name
115    ------------------------------------------------------------
116    begin
117      deallocate(NamePtr) ;
118    end procedure Clear ;
119
120    ------------------------------------------------------------
121    procedure Deallocate is  -- clear name
122    ------------------------------------------------------------
123    begin
124      Clear ;
125    end procedure Deallocate ;
126
127  end protected body NamePType ;
128
129end package body NamePkg ;