ESRISystem interfaces


The System library within ArcGIS Engine, which is included with ArcSDK.h, contains a number of interfaces that simplify programming. It contains components that expose services used by the other ArcGIS libraries.

Groups of Objects in Interfaces without STL

ArcObjects contains several interfaces for managing groups of objects. Although they are not all discussed here, the examples given illustrate some that can greatly simplify your work with COM objects in C++. Standard Template Library (STL) types exist which are similar to some of these; however, these interfaces are often simpler than their STL counterparts and are already set up to be used with COM objects. For additional details on any of the interfaces below, see ArcGIS Developer Help for C++.

IArray

The IArray interface provides access to members that control a simple array of objects. There are multiple related interfaces, such as IDoubleArray and IVariantArray. The following code snippet shows how to add the geometries of the features in a FeatureCursor to an array.
For the sake of simplicity, the code snippets given don't always check HRESULT's, although as a developer you should always do so.
[C++]
// ipFeatureLayer is of type IFeatureLayerPtr and ipQueryFilter is of
// type IQueryFilterPtr. Both have already been declared and
// instantiated.
IArrayPtr ipCacheArray(CLSID_Array);
IFeatureCursorPtr ipFeatureCursor;
ipFeatureLayer->Search(ipQueryFilter, VARIANT_FALSE, &ipFeatureCursor);
IFeaturePtr ipFeature;
while (ipFeatureCursor->NextFeature(&ipFeature) == S_OK)
{
  IGeometryPtr ipGeom;
  ipFeature->get_ShapeCopy(&ipGeom);
  ipCacheArray->Add((IUnknownPtr)ipGeom);
}

ISet

The ISet interface provides access to members that control a simple set of unique objects. For example, the following code snippet cycles through a map's layers and attempts to add all of the unique feature class workspaces that aren't being edited to a set.
[C++]
// ipMap is of type IMapPtr and was previously declared and instantiated
ISetPtr ipSet(CLSID_Set);
ILayerPtr ipLayer;
IFeatureLayerPtr ipFeatLayer;
IFeatureClassPtr ipFeatClass;
IDatasetPtr ipDataset;
IWorkspacePtr ipWorkspace;
IWorkspaceEditPtr ipWorkspaceEdit;
long layerCount;
hr = ipMap->get_LayerCount(&layerCount);
for (long i = 0; i < layerCount; i++)
{
  hr = ipMap->get_Layer(i, &ipLayer);
  ipFeatLayer = ipLayer;
  // layer might not be a feature layer
  if (ipFeatLayer == 0 || FAILED(hr))
    continue;
  hr = ipFeatLayer->get_FeatureClass(&ipFeatClass);
  // layer could reference bogus data
  if (ipFeatClass == 0 || FAILED(hr))
    continue;
  ipDataset = ipFeatClass;
  hr = ipDataset->get_Workspace(&ipWorkspace);
  ipWorkspaceEdit = ipWorkspace;
  // some data are not editable
  if (ipWorkspaceEdit == 0 || FAILED(hr))
    continue;
  VARIANT_BOOL beingEdited;
  hr = ipWorkspaceEdit->IsBeingEdited(&beingEdited);
  if (!beingEdited)
  {
    // only adds unique workspaces
    hr = ipSet->Add(ipWorkspace);
  }
}

Copy objects — IClone

The IClone interface is helpful when comparing and copying objects, saving time and computing resources. Many coclasses support the IClone interface. See the documentation for IClone in ArcGIS Developer Help for details. The following code snippet clones a Point object:
[C++]
// ipMouseClickPoint is of type IPointPtr and was previously declared 
and instantiated. IClonePtr ipClone(ipMouseClickPoint);
IClonePtr ipCloned;
ipClone->Clone(&ipCloned);

The IUID Object

There are several methods in ArcObjects that take an IUID object as a parameter. An IUID object is a globally unique identifier object. It can be either a GUID, as shown in the example below, or a ProgID.
[C++]
IUIDPtr ipUID(CLSID_UID);
IEnumLayerPtr ipEnumLayer;
// use IGeoFeatureLayer's GUID
hr = ipUID->put_Value(CComVariant(L "{E156D7E5-22AF-11D3-9F99-00C04F6BC78E}"));
hr = ipMap->get_Layers(ipUID, VARIANT_TRUE, &ipEnumLayer);
For further details on GUIDs, see the Introduction to COM section of this help system.