STLdoc
STLdocumentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
Concurrency::multi_link_registry< _Block > Class Template Reference

The multi_link_registry object is a network_link_registry that manages multiple source blocks or multiple target blocks. More...

#include <agents.h>

Inheritance diagram for Concurrency::multi_link_registry< _Block >:
Concurrency::network_link_registry< _Block >

Public Member Functions

 multi_link_registry ()
 Constructs a multi_link_registry object. More...
 
virtual ~multi_link_registry ()
 Destroys the multi_link_registry object. More...
 
void set_bound (size_t _MaxLinks)
 Sets an upper bound on the number of links that the multi_link_registry object can hold. More...
 
virtual void add (_EType _Link)
 Adds a link to the multi_link_registry object. More...
 
virtual bool remove (_EType _Link)
 Removes a link from the multi_link_registry object. More...
 
virtual bool contains (_EType _Link)
 Searches the multi_link_registry object for a specified block. More...
 
virtual size_t count ()
 Counts the number of items in the multi_link_registry object. More...
 
virtual iterator begin ()
 Returns an iterator to the first element in the multi_link_registry object. More...
 

Protected Member Functions

virtual void _Next_index (size_t &_Index)
 Skips empty slots and updates the index to the next non-empty slot. This is called by the iterator. More...
 
virtual _EType _Get_element (size_t _Index) const
 Retrieves the element at the given index. If the index is out of bounds, NULL is returned. Users need to use the iterator to access the links More...
 

Private Member Functions

void _Add (_EType _Link)
 Adds a link to the multi_link_registry object. More...
 
bool _Remove (_EType _Link)
 Removes a link from the multi_link_registry More...
 
virtual size_t _Find (_EType _Link)
 Searches the registry for the given link More...
 
size_t _Count () const
 Returns the count of items in the registry. More...
 

Private Attributes

size_t _M_maxLinks
 
::Concurrency::details::_Dynamic_array< _EType_M_vector
 

Static Private Attributes

static const size_t _NOT_SET = SIZE_MAX
 

Additional Inherited Members

Detailed Description

template<class _Block>
class Concurrency::multi_link_registry< _Block >

The multi_link_registry object is a network_link_registry that manages multiple source blocks or multiple target blocks.

Template Parameters
_BlockThe block data type being stored in the multi_link_registry object.
See also
single_link_registry Class

Constructor & Destructor Documentation

template<class _Block>
Concurrency::multi_link_registry< _Block >::multi_link_registry ( )
inline

Constructs a multi_link_registry object.

917  {
918  }
template<class _Block>
virtual Concurrency::multi_link_registry< _Block >::~multi_link_registry ( )
inlinevirtual

Destroys the multi_link_registry object.

The method throws an invalid_operation exception if called before all links are removed.

929  {
930  // It is an error to delete link registry with links
931  // still present
932  if (count() != 0)
933  {
934  throw invalid_operation("Deleting link registry before removing all the links");
935  }
936  }

Member Function Documentation

template<class _Block>
void Concurrency::multi_link_registry< _Block >::_Add ( _EType  _Link)
inlineprivate

Adds a link to the multi_link_registry object.

Parameters
_LinkA pointer to a block to be added.
1101  {
1102  size_t _Size = _M_vector._Size();
1103  size_t _Insert_pos = 0;
1104 
1106 
1107  // If max links is set, ensure that inserting the new
1108  // link will not exceed the bound.
1109  if ((_M_maxLinks != _NOT_SET) && ((_Size+1) > (size_t) _M_maxLinks))
1110  {
1111  throw invalid_link_target("_Link");
1112  }
1113 
1114  for (size_t _Index = 0; _Index < _Size; _Index++)
1115  {
1116  if (_M_vector[_Index] != NULL)
1117  {
1118  // We want to find the first NULL entry after all the
1119  // non-NULL entries.
1120  _Insert_pos = _Index + 1;
1121 
1122  // Throw if dupiclate entry is found
1123  if (_M_vector[_Index] == _Link)
1124  {
1125  throw invalid_link_target("_Link");
1126  }
1127  }
1128  }
1129 
1130  if (_Insert_pos < _Size)
1131  {
1132  _M_vector[_Insert_pos] = _Link;
1133  }
1134  else
1135  {
1137  }
1138  }
#define _CONCRT_ASSERT(x)
Definition: concrt.h:137
_FS_DLL int __CLRCALL_PURE_OR_CDECL _Link(const char *, const char *)
void _Push_back(_Type const &_Element)
Definition: agents.h:318
#define NULL
Definition: crtdbg.h:30
size_t _Size() const
Definition: agents.h:353
_Check_return_ _In_ long _Size
Definition: io.h:325
template<class _Block>
size_t Concurrency::multi_link_registry< _Block >::_Count ( ) const
inlineprivate

Returns the count of items in the registry.

Returns
The count of items in the registry.
1207  {
1208  size_t _Count = 0;
1209 
1210  for (size_t _Index = 0; _Index < _M_vector._Size(); _Index++)
1211  {
1212  if (_M_vector[_Index] != NULL)
1213  {
1214  _Count++;
1215  }
1216  }
1217 
1218  return _Count;
1219  }
#define NULL
Definition: crtdbg.h:30
size_t _Size() const
Definition: agents.h:353
template<class _Block>
virtual size_t Concurrency::multi_link_registry< _Block >::_Find ( _EType  _Link)
inlineprivatevirtual

Searches the registry for the given link

Parameters
_LinkA pointer to a block that is to be searched.
Returns
Index of the entry if found.
1186  {
1187  size_t _Index = 0;
1188  for (_Index = 0; _Index < _M_vector._Size(); _Index++)
1189  {
1190  if (_M_vector[_Index] == _Link)
1191  {
1192  break;
1193  }
1194  }
1195 
1196  return _Index;
1197  }
_FS_DLL int __CLRCALL_PURE_OR_CDECL _Link(const char *, const char *)
size_t _Size() const
Definition: agents.h:353
template<class _Block>
virtual _EType Concurrency::multi_link_registry< _Block >::_Get_element ( size_t  _Index) const
inlineprotectedvirtual

Retrieves the element at the given index. If the index is out of bounds, NULL is returned. Users need to use the iterator to access the links

Parameters
_IndexIndex of the link to be retrieved.
Returns
The element in the registry at the index specified by the _Index parameter.

Implements Concurrency::network_link_registry< _Block >.

1082  {
1083  if (_Index < _M_vector._Size())
1084  {
1085  return _M_vector[_Index];
1086  }
1087 
1088  return NULL;
1089  }
#define NULL
Definition: crtdbg.h:30
size_t _Size() const
Definition: agents.h:353
template<class _Block>
virtual void Concurrency::multi_link_registry< _Block >::_Next_index ( size_t _Index)
inlineprotectedvirtual

Skips empty slots and updates the index to the next non-empty slot. This is called by the iterator.

Parameters
_IndexA reference to the index that is to be updated.

Implements Concurrency::network_link_registry< _Block >.

1057  {
1058  size_t _Size = _M_vector._Size();
1059  while (_Index < _Size)
1060  {
1061  if (_M_vector[_Index] != NULL)
1062  {
1063  break;
1064  }
1065 
1066  ++_Index;
1067  }
1068  }
#define NULL
Definition: crtdbg.h:30
size_t _Size() const
Definition: agents.h:353
_Check_return_ _In_ long _Size
Definition: io.h:325
template<class _Block>
bool Concurrency::multi_link_registry< _Block >::_Remove ( _EType  _Link)
inlineprivate

Removes a link from the multi_link_registry

Parameters
_LinkA pointer to a block to be removed, if found.
Returns
true if the specified link was found and removed, false otherwise.
1151  {
1153 
1154  for (size_t _Index = 0; _Index < _M_vector._Size(); _Index++)
1155  {
1156  if (_M_vector[_Index] == _Link)
1157  {
1158  _M_vector[_Index] = NULL;
1159 
1160  // If max links is set, prevent new additions to the registry
1161  if (_M_maxLinks != _NOT_SET && _M_maxLinks > 0)
1162  {
1163  // Setting the bound to 0. This causes add to always throw.
1164  _M_maxLinks = 0;
1165  }
1166 
1167  return true;
1168  }
1169  }
1170 
1171  return false;
1172  }
#define _CONCRT_ASSERT(x)
Definition: concrt.h:137
_FS_DLL int __CLRCALL_PURE_OR_CDECL _Link(const char *, const char *)
#define NULL
Definition: crtdbg.h:30
size_t _Size() const
Definition: agents.h:353
template<class _Block>
virtual void Concurrency::multi_link_registry< _Block >::add ( _EType  _Link)
inlinevirtual

Adds a link to the multi_link_registry object.

Parameters
_LinkA pointer to a block to be added.

The method throws an invalid_link_target exception if the link is already present in the registry, or if a bound has already been set with the set_bound function and a link has since been removed.

Implements Concurrency::network_link_registry< _Block >.

970  {
971  if (_Link == NULL)
972  {
973  return;
974  }
975 
976  _Add(_Link);
977  }
_FS_DLL int __CLRCALL_PURE_OR_CDECL _Link(const char *, const char *)
#define NULL
Definition: crtdbg.h:30
template<class _Block>
virtual iterator Concurrency::multi_link_registry< _Block >::begin ( )
inlinevirtual

Returns an iterator to the first element in the multi_link_registry object.

The end state is indicated by a NULL link.

Returns
An iterator addressing the first element in the multi_link_registry object.

Implements Concurrency::network_link_registry< _Block >.

1042  {
1043  return (iterator(this, 0));
1044  }
template<class _Block>
virtual bool Concurrency::multi_link_registry< _Block >::contains ( _EType  _Link)
inlinevirtual

Searches the multi_link_registry object for a specified block.

Parameters
_LinkA pointer to a block that is to be searched for in the multi_link_registry object.
Returns
true if the specified block was found, false otherwise.

Implements Concurrency::network_link_registry< _Block >.

1010  {
1011  if (_Link == NULL)
1012  {
1013  return false;
1014  }
1015 
1016  return (_Find(_Link) < _M_vector._Size());
1017  }
_FS_DLL int __CLRCALL_PURE_OR_CDECL _Link(const char *, const char *)
#define NULL
Definition: crtdbg.h:30
size_t _Size() const
Definition: agents.h:353
template<class _Block>
virtual size_t Concurrency::multi_link_registry< _Block >::count ( )
inlinevirtual

Counts the number of items in the multi_link_registry object.

Returns
The number of items in the multi_link_registry object.

Implements Concurrency::network_link_registry< _Block >.

1027  {
1028  return _Count();
1029  }
template<class _Block>
virtual bool Concurrency::multi_link_registry< _Block >::remove ( _EType  _Link)
inlinevirtual

Removes a link from the multi_link_registry object.

Parameters
_LinkA pointer to a block to be removed, if found.
Returns
true if the link was found and removed, false otherwise.

Implements Concurrency::network_link_registry< _Block >.

990  {
991  if (_Link == NULL)
992  {
993  return false;
994  }
995 
996  return (_Remove(_Link));
997  }
_FS_DLL int __CLRCALL_PURE_OR_CDECL _Link(const char *, const char *)
#define NULL
Definition: crtdbg.h:30
template<class _Block>
void Concurrency::multi_link_registry< _Block >::set_bound ( size_t  _MaxLinks)
inline

Sets an upper bound on the number of links that the multi_link_registry object can hold.

Parameters
_MaxLinksThe maximum number of links that the multi_link_registry object can hold.

After a bound is set, unlinking an entry will cause the multi_link_registry object to enter an immutable state where further calls to add will throw an invalid_link_target exception.

952  {
953  _CONCRT_ASSERT(count() == 0);
954  _M_maxLinks = _MaxLinks;
955  }
#define _CONCRT_ASSERT(x)
Definition: concrt.h:137

Member Data Documentation

template<class _Block>
size_t Concurrency::multi_link_registry< _Block >::_M_maxLinks
private
template<class _Block>
::Concurrency::details::_Dynamic_array<_EType> Concurrency::multi_link_registry< _Block >::_M_vector
private
template<class _Block>
const size_t Concurrency::multi_link_registry< _Block >::_NOT_SET = SIZE_MAX
staticprivate

The documentation for this class was generated from the following file: