1515* Last change:
1616********************************************************************/
1717
18-
19- #include < string.h> /* memcpy() */
20-
2118#include " rcs.hh" // LinkedList
2219#include " interpl.hh" // these decls
2320#include " emc.hh"
2421#include " emcglb.h"
25- #include " linklist.hh"
2622#include " nmlmsg.hh" /* class NMLmsg */
2723#include " rcs_print.hh"
2824
2925NML_INTERP_LIST interp_list; /* NML Union, for interpreter */
3026
31- NML_INTERP_LIST::NML_INTERP_LIST ()
32- {
33- linked_list_ptr = new LinkedList;
34-
35- next_line_number = 0 ;
36- line_number = 0 ;
37- }
38-
39- NML_INTERP_LIST::~NML_INTERP_LIST ()
40- {
41- if (NULL != linked_list_ptr) {
42- delete linked_list_ptr;
43- linked_list_ptr = NULL ;
44- }
45- }
46-
4727int NML_INTERP_LIST::append (NMLmsg & nml_msg)
4828{
4929 return append (&nml_msg);
5030}
5131
5232// sets the line number used for subsequent appends
53- int NML_INTERP_LIST::set_line_number (int line)
33+ void NML_INTERP_LIST::set_line_number (int line)
5434{
5535 next_line_number = line;
56-
57- return 0 ;
5836}
5937
6038int NML_INTERP_LIST::append (NMLmsg * nml_msg_ptr)
@@ -72,11 +50,6 @@ int NML_INTERP_LIST::append(NMLmsg * nml_msg_ptr)
7250 return -1 ;
7351 }
7452
75- if (nml_msg_ptr->size > MAX_NML_COMMAND_SIZE - 64 ) {
76- rcs_print_error
77- (" NML_INTERP_LIST::append : command size is too large." );
78- return -1 ;
79- }
8053 if (nml_msg_ptr->size < 4 ) {
8154 rcs_print_error
8255 (" NML_INTERP_LIST::append : command size is invalid." );
@@ -93,28 +66,21 @@ int NML_INTERP_LIST::append(NMLmsg * nml_msg_ptr)
9366 }
9467#endif
9568
96- if ( NULL == linked_list_ptr) {
97- return - 1 ;
98- }
69+ NML_INTERP_LIST_NODE node;
70+ node. line_number = next_line_number ;
71+ node. command . reserve (nml_msg_ptr-> size );
9972 // fill in the NML_INTERP_LIST_NODE
100- temp_node.line_number = next_line_number;
101- memcpy (temp_node.command .commandbuf , nml_msg_ptr, nml_msg_ptr->size );
73+ node.command .insert (node.command .begin (), (char *)nml_msg_ptr, (char *)nml_msg_ptr + nml_msg_ptr->size );
10274
10375 // stick it on the list
104- linked_list_ptr->store_at_tail (&temp_node,
105- nml_msg_ptr->size +
106- sizeof (temp_node.line_number ) +
107- sizeof (temp_node.dummy ) + 32 + (32 -
108- nml_msg_ptr->
109- size %
110- 32 ), 1 );
76+ linked_list.push_back (node);
11177
11278 if (emc_debug & EMC_DEBUG_INTERP_LIST) {
11379 rcs_print
114- (" NML_INTERP_LIST(%p)::append(nml_msg_ptr{size=%ld,type=%s}) : list_size=%d , line_number=%d\n " ,
80+ (" NML_INTERP_LIST(%p)::append(nml_msg_ptr{size=%ld,type=%s}) : list_size=%lu , line_number=%d\n " ,
11581 this ,
11682 nml_msg_ptr->size , emc_symbol_lookup (nml_msg_ptr->type ),
117- linked_list_ptr-> list_size , temp_node .line_number );
83+ linked_list. size (), node .line_number );
11884 }
11985
12086 return 0 ;
@@ -123,32 +89,27 @@ int NML_INTERP_LIST::append(NMLmsg * nml_msg_ptr)
12389NMLmsg *NML_INTERP_LIST::get ()
12490{
12591 NMLmsg *ret;
126- NML_INTERP_LIST_NODE *node_ptr;
12792
128- if ( NULL == linked_list_ptr) {
129- line_number = 0 ;
130- return NULL ;
93+ if (linked_list. empty ()) {
94+ line_number = 0 ;
95+ return NULL ;
13196 }
13297
133- node_ptr = (NML_INTERP_LIST_NODE *) linked_list_ptr->retrieve_head ();
98+ // get it off the front
99+ node = linked_list.front ();
100+ linked_list.pop_front ();
134101
135- if (NULL == node_ptr) {
136- line_number = 0 ;
137- return NULL ;
138- }
139102 // save line number of this one, for use by get_line_number
140- line_number = node_ptr->line_number ;
141-
142- // get it off the front
143- ret = (NMLmsg *) ((char *) node_ptr->command .commandbuf );
103+ line_number = node.line_number ;
104+ ret = (NMLmsg *) node.command .data ();
144105
145106 if (emc_debug & EMC_DEBUG_INTERP_LIST) {
146107 rcs_print (
147- " NML_INTERP_LIST(%p)::get(): {size=%ld, type=%s}, list_size=%d \n " ,
108+ " NML_INTERP_LIST(%p)::get(): {size=%ld, type=%s}, list_size=%lu \n " ,
148109 this ,
149110 ret->size ,
150111 emc_symbol_lookup (ret->type ),
151- linked_list_ptr-> list_size
112+ linked_list. size ()
152113 );
153114 }
154115
@@ -157,45 +118,27 @@ NMLmsg *NML_INTERP_LIST::get()
157118
158119void NML_INTERP_LIST::clear ()
159120{
160- if (NULL != linked_list_ptr) {
161- if (emc_debug & EMC_DEBUG_INTERP_LIST) {
162- rcs_print (" NML_INTERP_LIST(%p)::clear(): discarding %d items\n " , this , linked_list_ptr->list_size );
163- }
164-
165- linked_list_ptr->delete_members ();
121+ if (emc_debug & EMC_DEBUG_INTERP_LIST) {
122+ rcs_print (" NML_INTERP_LIST(%p)::clear(): discarding %lu items\n " , this , linked_list.size ());
166123 }
124+ linked_list.clear ();
167125}
168126
169127void NML_INTERP_LIST::print ()
170128{
171- NMLmsg *ret;
172- NML_INTERP_LIST_NODE *node_ptr;
173- int line_number;
129+ NMLmsg *msg;
174130
175- if (NULL == linked_list_ptr) {
176- return ;
177- }
178- node_ptr = (NML_INTERP_LIST_NODE *) linked_list_ptr->get_head ();
179-
180- rcs_print (" NML_INTERP_LIST::print(): list size=%d\n " ,linked_list_ptr->list_size );
181- while (NULL != node_ptr) {
182- line_number = node_ptr->line_number ;
183- ret = (NMLmsg *) ((char *) node_ptr->command .commandbuf );
184- rcs_print (" --> type=%s, line_number=%d\n " ,
185- emc_symbol_lookup ((int )ret->type ),
186- line_number);
187- node_ptr = (NML_INTERP_LIST_NODE *) linked_list_ptr->get_next ();
131+ rcs_print (" NML_INTERP_LIST::print(): list size=%lu\n " ,linked_list.size ());
132+ for (auto &i:linked_list){
133+ msg = (NMLmsg *) i.command .data ();
134+ rcs_print (" --> type=%s, line_number=%d\n " , emc_symbol_lookup (msg->type ), i.line_number );
188135 }
189136 rcs_print (" \n " );
190137}
191138
192139int NML_INTERP_LIST::len ()
193140{
194- if (NULL == linked_list_ptr) {
195- return 0 ;
196- }
197-
198- return ((int ) linked_list_ptr->list_size );
141+ return ((int ) linked_list.size ());
199142}
200143
201144int NML_INTERP_LIST::get_line_number ()
0 commit comments