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 (typename network_link_registry< _Block >::_EType _Link)
 Adds a link to the multi_link_registry object. More...
 
virtual bool remove (typename network_link_registry< _Block >::_EType _Link)
 Removes a link from the multi_link_registry object. More...
 
virtual bool contains (typename network_link_registry< _Block >::_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 network_link_registry< _Block >::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 network_link_registry< _Block >::_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 (typename network_link_registry< _Block >::_EType _Link)
 Adds a link to the multi_link_registry object. More...
 
bool _Remove (typename network_link_registry< _Block >::_EType _Link)
 Removes a link from the multi_link_registry More...
 
virtual size_t _Find (typename network_link_registry< _Block >::_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< typename network_link_registry< _Block >::_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.

918  {
919  }
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.

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

Member Function Documentation

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

Adds a link to the multi_link_registry object.

Parameters
_LinkA pointer to a block to be added.
1102  {
1103  size_t _Size = _M_vector._Size();
1104  size_t _Insert_pos = 0;
1105 
1107 
1108  // If max links is set, ensure that inserting the new
1109  // link will not exceed the bound.
1110  if ((_M_maxLinks != _NOT_SET) && ((_Size+1) > (size_t) _M_maxLinks))
1111  {
1112  throw invalid_link_target("_Link");
1113  }
1114 
1115  for (size_t _Index = 0; _Index < _Size; _Index++)
1116  {
1117  if (_M_vector[_Index] != NULL)
1118  {
1119  // We want to find the first NULL entry after all the
1120  // non-NULL entries.
1121  _Insert_pos = _Index + 1;
1122 
1123  // Throw if duplicate entry is found
1124  if (_M_vector[_Index] == _Link)
1125  {
1126  throw invalid_link_target("_Link");
1127  }
1128  }
1129  }
1130 
1131  if (_Insert_pos < _Size)
1132  {
1133  _M_vector[_Insert_pos] = _Link;
1134  }
1135  else
1136  {
1137  _M_vector._Push_back(_Link);
1138  }
1139  }
#define NULL
Definition: vcruntime.h:236
#define _CONCRT_ASSERT(x)
Definition: concrt.h:123
_FS_DLL int __CLRCALL_PURE_OR_CDECL _Link(const wchar_t *, const wchar_t *)
_Size
Definition: vcruntime_string.h:36
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.
1208  {
1209  size_t _Count = 0;
1210 
1211  for (size_t _Index = 0; _Index < _M_vector._Size(); _Index++)
1212  {
1213  if (_M_vector[_Index] != NULL)
1214  {
1215  _Count++;
1216  }
1217  }
1218 
1219  return _Count;
1220  }
#define NULL
Definition: vcruntime.h:236
template<class _Block>
virtual size_t Concurrency::multi_link_registry< _Block >::_Find ( typename network_link_registry< _Block >::_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.
1187  {
1188  size_t _Index = 0;
1189  for (_Index = 0; _Index < _M_vector._Size(); _Index++)
1190  {
1191  if (_M_vector[_Index] == _Link)
1192  {
1193  break;
1194  }
1195  }
1196 
1197  return _Index;
1198  }
_FS_DLL int __CLRCALL_PURE_OR_CDECL _Link(const wchar_t *, const wchar_t *)
template<class _Block>
virtual network_link_registry<_Block>::_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 >.

1083  {
1084  if (_Index < _M_vector._Size())
1085  {
1086  return _M_vector[_Index];
1087  }
1088 
1089  return NULL;
1090  }
#define NULL
Definition: vcruntime.h:236
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 >.

1058  {
1059  size_t _Size = _M_vector._Size();
1060  while (_Index < _Size)
1061  {
1062  if (_M_vector[_Index] != NULL)
1063  {
1064  break;
1065  }
1066 
1067  ++_Index;
1068  }
1069  }
#define NULL
Definition: vcruntime.h:236
_Size
Definition: vcruntime_string.h:36
template<class _Block>
bool Concurrency::multi_link_registry< _Block >::_Remove ( typename network_link_registry< _Block >::_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.
1152  {
1154 
1155  for (size_t _Index = 0; _Index < _M_vector._Size(); _Index++)
1156  {
1157  if (_M_vector[_Index] == _Link)
1158  {
1159  _M_vector[_Index] = NULL;
1160 
1161  // If max links is set, prevent new additions to the registry
1162  if (_M_maxLinks != _NOT_SET && _M_maxLinks > 0)
1163  {
1164  // Setting the bound to 0. This causes add to always throw.
1165  _M_maxLinks = 0;
1166  }
1167 
1168  return true;
1169  }
1170  }
1171 
1172  return false;
1173  }
#define NULL
Definition: vcruntime.h:236
#define _CONCRT_ASSERT(x)
Definition: concrt.h:123
_FS_DLL int __CLRCALL_PURE_OR_CDECL _Link(const wchar_t *, const wchar_t *)
template<class _Block>
virtual void Concurrency::multi_link_registry< _Block >::add ( typename network_link_registry< _Block >::_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.

971  {
972  if (_Link == NULL)
973  {
974  return;
975  }
976 
977  _Add(_Link);
978  }
#define NULL
Definition: vcruntime.h:236
_FS_DLL int __CLRCALL_PURE_OR_CDECL _Link(const wchar_t *, const wchar_t *)
template<class _Block>
virtual network_link_registry<_Block>::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 >.

1043  {
1044  return (typename network_link_registry<_Block>::iterator(this, 0));
1045  }
template<class _Block>
virtual bool Concurrency::multi_link_registry< _Block >::contains ( typename network_link_registry< _Block >::_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.
1011  {
1012  if (_Link == NULL)
1013  {
1014  return false;
1015  }
1016 
1017  return (_Find(_Link) < _M_vector._Size());
1018  }
#define NULL
Definition: vcruntime.h:236
_FS_DLL int __CLRCALL_PURE_OR_CDECL _Link(const wchar_t *, const wchar_t *)
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 >.

1028  {
1029  return _Count();
1030  }
template<class _Block>
virtual bool Concurrency::multi_link_registry< _Block >::remove ( typename network_link_registry< _Block >::_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.
991  {
992  if (_Link == NULL)
993  {
994  return false;
995  }
996 
997  return (_Remove(_Link));
998  }
#define NULL
Definition: vcruntime.h:236
_FS_DLL int __CLRCALL_PURE_OR_CDECL _Link(const wchar_t *, const wchar_t *)
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.

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

Member Data Documentation

template<class _Block>
size_t Concurrency::multi_link_registry< _Block >::_M_maxLinks
private
template<class _Block>
::Concurrency::details::_Dynamic_array<typename network_link_registry<_Block>::_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: