WebSphere Message Service Clients for C/C++ and .NET, Version 1.2 운영 체제: Linux, Windows

반복기

반복기는 목록에서 현재 위치를 유지하는 커서와 오브젝트의 목록을 캡슐화합니다. C 또는 C++ 응용프로그램은 반복기를 사용하여 목록의 각 오브젝트를 검색합니다.

반복기가 작성되면 커서의 위치는 첫번째 오브젝트의 앞에 옵니다. 응용프로그램은 반복기를 사용하여 각 오브젝트를 검색합니다. 오브젝트를 검색하기 위해 응용프로그램은 Iterator 클래스의 다음 세 메소드를 사용합니다.

Iterator 클래스는 Java의 Enumerator 클래스와 같습니다. XMS .NET은 Java와 비슷하며 IEnumerator 인터페이스를 사용합니다.

응용프로그램은 반복기를 사용하여 다음 타스크를 수행할 수 있습니다.
다음 코드 단편은 C 응용프로그램이 반복기를 사용하여 메시지의 모든 등록 정보를 인쇄하는 방법을 설명합니다.
/********************************************************/
/* XMS Sample using an iterator to browse properties    */
/********************************************************/
rc = xmsMsgGetProperties(hMsg, &it, xmsError);
if (rc == XMS_OK)
{
  rc = xmsIteratorHasNext(it, &more, xmsError);
  while (more)
  {
    rc = xmsIteratorGetNextProperty(it, (xmsHObj)&p, xmsError);
    if (rc == XMS_OK)
    {
      xmsPropertyGetName(p, name, 100, &len, xmsError);
      printf("Property name=\"%s\"\n", name);
      xmsPropertyGetTypeId(p, &type, xmsError);
      switch (type)
      {
        case XMS_PROPERTY_TYPE_INT:
        {
          xmsINT value=0;
          xmsPropertyGetInt(p, &value, xmsError);
          printf("Property value=%d\n", value);
          break;
        }
        case XMS_PROPERTY_TYPE_STRING:
        {
          xmsINT len=0;
          char value[100];
          xmsPropertyGetString(p, value, 100, &len, xmsError);
          printf("Property value=\"%s\"\n", value);
          break;
        }
        default:
        {
          printf("Unhandled property type (%d)\n", (int)type);
        }
      }
      xmsPropertyDispose(&p, xmsError);
    }
    rc = xmsIteratorHasNext(it, &more, xmsError);
  }
  printf("Finished iterator....\n");
  xmsIteratorDispose(&it, xmsError);
}
/********************************************************/

Concept topic

이용약관 | 피드백

Timestamp icon마지막 갱신 날짜: 3 Mar 2006
(C) Copyright IBM Corporation 2005. All Rights Reserved.
이 Information Center는 Eclipse 기술 기반입니다. (http://www.eclipse.org 웹 사이트 참조)