Skip to content

Commit 98cf176

Browse files
authored
Merge pull request #2486 from rene-dev/libstd2
change interpl linked list to std::deque
2 parents 0d1d7f8 + 27713d7 commit 98cf176

2 files changed

Lines changed: 36 additions & 114 deletions

File tree

src/emc/nml_intf/interpl.cc

Lines changed: 27 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -15,46 +15,24 @@
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

2925
NML_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-
4727
int 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

6038
int 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)
12389
NMLmsg *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

158119
void 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

169127
void 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

192139
int 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

201144
int NML_INTERP_LIST::get_line_number()

src/emc/nml_intf/interpl.hh

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17,40 +17,19 @@
1717
#ifndef INTERP_LIST_HH
1818
#define INTERP_LIST_HH
1919

20-
#include <stdint.h>
21-
22-
#define MAX_NML_COMMAND_SIZE 1000
20+
#include <deque>
21+
#include <vector>
2322

2423
// these go on the interp list
2524
struct NML_INTERP_LIST_NODE {
26-
int line_number; // line number it was on
27-
union _dummy_union {
28-
int32_t i;
29-
int32_t l;
30-
double d;
31-
float f;
32-
int64_t ll;
33-
long double ld;
34-
} dummy; // paranoid alignment variable.
35-
36-
union _command_union {
37-
char commandbuf[MAX_NML_COMMAND_SIZE]; // the NML command;
38-
int32_t i;
39-
int32_t l;
40-
double d;
41-
float f;
42-
int64_t ll;
43-
long double ld;
44-
} command;
25+
int line_number; // line number it was on
26+
std::vector<char> command;
4527
};
4628

4729
// here's the interp list itself
4830
class NML_INTERP_LIST {
4931
public:
50-
NML_INTERP_LIST();
51-
~NML_INTERP_LIST();
52-
53-
int set_line_number(int line);
32+
void set_line_number(int line);
5433
int get_line_number();
5534
int append(NMLmsg &);
5635
int append(NMLmsg *);
@@ -60,10 +39,10 @@ class NML_INTERP_LIST {
6039
int len();
6140

6241
private:
63-
class LinkedList * linked_list_ptr;
64-
NML_INTERP_LIST_NODE temp_node; // filled in and put on the list
65-
int next_line_number; // line number used to fill temp_node
66-
int line_number; // line number of node from get()
42+
std::deque<NML_INTERP_LIST_NODE> linked_list;
43+
int next_line_number = 0; // line number used to fill temp_node
44+
int line_number = 0; // line number of node from get()
45+
NML_INTERP_LIST_NODE node; // pointer returned by get
6746
};
6847

6948
extern NML_INTERP_LIST interp_list; /* NML Union, for interpreter */

0 commit comments

Comments
 (0)