반복기는 목록에서 현재 위치를 유지하는 커서와 오브젝트의 목록을 캡슐화합니다. C 또는 C++ 응용프로그램은 반복기를 사용하여 목록의 각 오브젝트를 검색합니다.
반복기가 작성되면 커서의 위치는 첫번째 오브젝트의 앞에 옵니다. 응용프로그램은 반복기를 사용하여 각 오브젝트를 검색합니다. 오브젝트를 검색하기 위해 응용프로그램은 Iterator 클래스의 다음 세 메소드를 사용합니다.
Iterator 클래스는 Java의 Enumerator 클래스와 같습니다. XMS .NET은 Java와 비슷하며 IEnumerator 인터페이스를 사용합니다.
/********************************************************/ /* 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); } /********************************************************/