OpenCores
URL https://opencores.org/ocsvn/sv_dir_tb/sv_dir_tb/trunk

Subversion Repositories sv_dir_tb

[/] [sv_dir_tb/] [trunk/] [sv/] [lst_item.sv] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 sckoarn
////////////////////////////////////////////////////////////////////////////
2
//
3
// Copyright 2014  Ken Campbell
4
//
5
//   Licensed under the Apache License, Version 2.0 (the "License");
6
//   you may not use this file except in compliance with the License.
7
//   You may obtain a copy of the License at
8
//
9
//     http://www.apache.org/licenses/LICENSE-2.0
10
//
11
//   Unless required by applicable law or agreed to in writing, software
12
//   distributed under the License is distributed on an "AS IS" BASIS,
13
//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
//   See the License for the specific language governing permissions and
15
//   limitations under the License.
16
//
17
/////////////////////////////////////
18
 
19
  ////////////////////////////////
20
  //  list class.  enables a list of items to be
21
  //      created and accessed by an index or text.
22
typedef class lst_item;
23
class lst_item;
24
  string  name;
25
  string  txt;
26
  integer val;
27
  integer index;
28
  lst_item next;
29
  lst_item prev;
30
 
31
  extern function new(string ID);
32
  extern function void print();
33
  extern function void add_itm(lst_item item);
34
  extern function lst_item get(integer idx);
35
  extern function lst_item find(string txt);
36
  extern function void set(integer idx, integer val);
37
 
38
endclass // lst_item
39
 
40
  /////////////////////////////////////////////////
41
  //  lst_item methods
42
  //   function lst_item::new
43
  function lst_item::new(string ID);
44
    name = ID;
45
    txt  =   "";
46
    val  =   0;
47
    index =  0;
48
    next  =  null;
49
    prev  =  null;
50
  endfunction // new
51
 
52
//////////////////////////////////////////////////
53
  // function lst_item::print
54
  function void lst_item::print();
55
    lst_item lst;
56
    lst = this;
57
    while(lst != null) begin
58
      $display("%s  %s  %d  %d", lst.name, lst.txt, lst.val, lst.index);
59
      lst = lst.next;
60
    end
61
    //$display("%s  %s  %d  %d", lst.name, lst.txt, lst.val, lst.index);
62
  endfunction // print
63
 
64
////////////////////////////////////////////////////////
65
  //  function lst_item::set
66
  function void lst_item::set(integer idx, integer val);
67
    lst_item  tmp_itm;
68
 
69
    tmp_itm  =  this;
70
    while (tmp_itm != null) begin
71
      if (tmp_itm.index == idx) begin
72
        tmp_itm.val = val;
73
        break;
74
      end
75
      tmp_itm = tmp_itm.next;
76
    end
77
 
78
  endfunction  //  lst_item::set
79
 
80
/////////////////////////////////////////////////
81
  //  function  lst_item::add_itm
82
  function void lst_item::add_itm(lst_item item);
83
    lst_item tmp_itm;
84
    lst_item new_itm;
85
    tmp_itm  =  this;
86
    //  first item
87
    if((tmp_itm.next == null) && (tmp_itm.txt == ""))begin
88
      tmp_itm.txt = item.txt;
89
      tmp_itm.val = item.val;
90
      tmp_itm.prev = null;
91
    // second item
92
    end else if((tmp_itm.next == null) && (tmp_itm.txt != ""))begin
93
      new_itm = new("");
94
      new_itm.index = tmp_itm.index + 1;
95
      new_itm.txt   = item.txt;
96
      new_itm.val   = item.val;
97
      tmp_itm.next  = new_itm;
98
      new_itm.prev  = tmp_itm;
99
    //  other items
100
    end else begin
101
      while (tmp_itm.next != null) begin
102
        tmp_itm = tmp_itm.next;
103
      end
104
      new_itm = new("");
105
      new_itm.index = tmp_itm.index + 1;
106
      new_itm.txt   = item.txt;
107
      new_itm.val   = item.val;
108
      tmp_itm.next  = new_itm;
109
      new_itm.prev  = tmp_itm;
110
    end
111
    //this = tmp_itm;
112
  endfunction // lst_item::add_itm
113
 
114
////////////////////////////////////////////////////////////
115
  //  function  lst_item::get  index
116
  function lst_item lst_item::get(integer idx);
117
    lst_item tmp_itm;
118
    tmp_itm  = new("");
119
    tmp_itm  =  this;
120
    while (tmp_itm != null) begin
121
      if (tmp_itm.index == idx) begin
122
        return tmp_itm;
123
      end
124
      tmp_itm = tmp_itm.next;
125
    end
126
 
127
    check_lst_item_get : assert (tmp_itm) else begin
128
      $warning("Item index  >>> %4d <<< was not found on the %s list.", idx, this.name);
129
    end
130
    //if (tmp_itm.index != idx) begin
131
    //  $display("ERROR: lst_item.get  Index not found !!  Returning NULL object");
132
    //  tmp_itm  = new("");
133
    //  return tmp_itm;
134
    //end
135
 
136
    return tmp_itm;
137
  endfunction // get
138
 
139
///////////////////////////////////////////////////////////
140
  //  function  lst_item::find  txt
141
  function lst_item lst_item::find(string txt);
142
    lst_item tmp_itm;
143
    tmp_itm  = new("");
144
    tmp_itm  =  this;
145
    //  go through the list
146
    while (tmp_itm != null) begin
147
      if (tmp_itm.txt == txt) begin
148
        break;
149
      end
150
      tmp_itm = tmp_itm.next;
151
    end
152
    //  check for  found
153
    check_lst_item_find : assert (tmp_itm) else begin
154
      $warning("Item >>> %s <<< was not found on the %s list.", txt, this.name);
155
    end
156
    return tmp_itm;
157
  endfunction //  find

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.