opennurbs_function_list.h
1 /* $NoKeywords: $ */
2 /*
3 //
4 // Copyright (c) 1993-2013 Robert McNeel & Associates. All rights reserved.
5 // OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
6 // McNeel & Associates.
7 //
8 // THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
9 // ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
10 // MERCHANTABILITY ARE HEREBY DISCLAIMED.
11 //
12 // For complete openNURBS copyright information see <http://www.opennurbs.org>.
13 //
14 ////////////////////////////////////////////////////////////////
15 */
16 
17 
18 #if !defined(OPENNURBS_FUNCTION_LIST_INC_)
19 #define OPENNURBS_FUNCTION_LIST_INC_
20 
21 class ON_CLASS ON_FunctionList
22 {
23 public:
24  /*
25  Parameters:
26  function_count_estimate - [in]
27  An estimate of the maximum number of functions that will
28  be in the list at any one time. Pass 0 if you don't know.
29  */
31  size_t function_count_estimate
32  );
33 
34  ~ON_FunctionList();
35 
36  /*
37  Description:
38  Unconditionally add a function to the list.
39  Parameters:
40  function - [in]
41  A function that takes a single ON__UINT_PTR parameter.
42  function_parameter - [in]
43  Returns:
44  0: list in use
45  1: function added
46  2: invalid input
47  */
48  unsigned int AddFunction(
49  void (*function)(ON__UINT_PTR),
50  ON__UINT_PTR function_parameter
51  );
52 
53  /*
54  Returns:
55  0: list in use
56  1: function removed
57  2: matching function not in the list
58  */
59  unsigned int RemoveFunction(
60  void (*function)(ON__UINT_PTR)
61  );
62 
63  /*
64  Returns:
65  0: list in use
66  1: function removed
67  2: matching function not in the list
68  */
69  unsigned int RemoveFunction(
70  void (*function)(ON__UINT_PTR),
71  ON__UINT_PTR function_parameter
72  );
73 
74  /*
75  Returns:
76  0: Matching function and parameter are not in the list.
77  1: Matching function and parameter are in the list.
78  2: list in use
79  */
80  unsigned int IsInList(
81  void (*function)(ON__UINT_PTR),
82  ON__UINT_PTR function_parameter
83  ) const;
84 
85  /*
86  Returns:
87  0: list in use
88  1: Matching function is in the list.
89  2: Matching function is not in the list.
90  */
91  unsigned int IsInList(
92  void (*function)(ON__UINT_PTR)
93  ) const;
94 
95  /*
96  Returns:
97  0: list in use
98  1: list was emptied
99  */
100  bool EmptyList();
101 
102  /*
103  Description:
104  Call all the functions in the function list.
105  Parameters:
106  bFirstToLast - [in]
107  true - function are called in the order added
108  false - functions are called in the reverse order added
109  Returns:
110  True if the functions were called or the list is empty.
111  False if the list is in use.
112  */
113  bool CallFunctions(
114  bool bFirstToLast
115  );
116 
117  /*
118  Returns:
119  True if the list is in use.
120  */
121  bool InUse() const;
122 
123  unsigned int FunctionCount() const;
124 
125 private:
126  ON_FixedSizePool m_fsp;
127  void* m_head = nullptr;
128  void* m_tail = nullptr;
129  mutable ON_Lock m_lock;
130 };
131 
132 #endif
ON_Lock is a thread safe lock semephore. It is implemented using platform specfic compare and set fun...
Definition: opennurbs_lock.h:24
Definition: opennurbs_fsp.h:19
Definition: opennurbs_function_list.h:21