Freeciv21
Develop your civilization from humble roots to a global empire
worklist.h
Go to the documentation of this file.
1 /*__ ___ ***************************************
2 / \ / \ Copyright (c) 1996-2020 Freeciv21 and Freeciv
3 \_ \ / __/ contributors. This file is part of Freeciv21.
4  _\ \ / /__ Freeciv21 is free software: you can redistribute it
5  \___ \____/ __/ and/or modify it under the terms of the GNU General
6  \_ _/ Public License as published by the Free Software
7  | @ @ \_ Foundation, either version 3 of the License,
8  | or (at your option) any later version.
9  _/ /\ You should have received a copy of the GNU
10  /o) (o/\ \_ General Public License along with Freeciv21.
11  \_____/ / If not, see https://www.gnu.org/licenses/.
12  \____/ ********************************************************/
13 #pragma once
14 
15 #include "registry.h"
16 
17 #include "fc_types.h"
18 
19 #define MAX_LEN_WORKLIST 64
20 #define MAX_NUM_WORKLISTS 16
21 
22 // a worklist
23 struct worklist {
24  int length;
26 };
27 
28 void worklist_init(struct worklist *pwl);
29 
30 int worklist_length(const struct worklist *pwl);
31 bool worklist_is_empty(const struct worklist *pwl);
32 bool worklist_peek(const struct worklist *pwl, struct universal *prod);
33 bool worklist_peek_ith(const struct worklist *pwl, struct universal *prod,
34  int idx);
35 void worklist_advance(struct worklist *pwl);
36 
37 void worklist_copy(struct worklist *dst, const struct worklist *src);
38 void worklist_remove(struct worklist *pwl, int idx);
39 bool worklist_append(struct worklist *pwl, const struct universal *prod);
40 bool worklist_insert(struct worklist *pwl, const struct universal *prod,
41  int idx);
42 // Used in packets_gen.cpp
43 bool are_worklists_equal(const struct worklist *wlist1,
44  const struct worklist *wlist2);
45 
46 // Iterate over all entries in the worklist.
47 #define worklist_iterate(_list, _p) \
48  { \
49  struct universal _p; \
50  int _p##_index = 0; \
51  \
52  while (_p##_index < worklist_length(_list)) { \
53  worklist_peek_ith(_list, &_p, _p##_index++);
54 
55 #define worklist_iterate_end \
56  } \
57  }
struct universal entries[MAX_LEN_WORKLIST]
Definition: worklist.h:25
int length
Definition: worklist.h:24
void worklist_advance(struct worklist *pwl)
Remove first element from worklist.
Definition: worklist.cpp:98
bool worklist_peek(const struct worklist *pwl, struct universal *prod)
Fill in the id and is_unit values for the head of the worklist if the worklist is non-empty.
Definition: worklist.cpp:70
void worklist_copy(struct worklist *dst, const struct worklist *src)
Copy contents from worklist src to worklist dst.
Definition: worklist.cpp:103
void worklist_init(struct worklist *pwl)
Initialize a worklist to be empty.
Definition: worklist.cpp:32
bool worklist_peek_ith(const struct worklist *pwl, struct universal *prod, int idx)
Fill in the id and is_unit values for the ith element in the worklist.
Definition: worklist.cpp:80
#define MAX_LEN_WORKLIST
Definition: worklist.h:19
bool worklist_is_empty(const struct worklist *pwl)
Returns whether worklist has no elements.
Definition: worklist.cpp:60
bool worklist_append(struct worklist *pwl, const struct universal *prod)
Adds the id to the next available slot in the worklist.
Definition: worklist.cpp:138
bool worklist_insert(struct worklist *pwl, const struct universal *prod, int idx)
Inserts the production at the location idx in the worklist, thus moving all subsequent entries down.
Definition: worklist.cpp:158
void worklist_remove(struct worklist *pwl, int idx)
Remove element from position idx.
Definition: worklist.cpp:113
bool are_worklists_equal(const struct worklist *wlist1, const struct worklist *wlist2)
Return TRUE iff the two worklists are equal.
Definition: worklist.cpp:183
int worklist_length(const struct worklist *pwl)
Returns the number of entries in the worklist.
Definition: worklist.cpp:51