Using Find |
There
are two types of find operations allowed on any object that inherits from
the class os_element_group .
Use the function find_first()
to find the first instance of a key and return a pointer to the element. If no
matching element is found, find_first() returns a
pointer with a value of 0 (zero).
In the following example, a key
named mykey is given to
the text element hello . When the function find_first()
is called, it iterates through the page and streams the first element with the
key mykey back to the page. This results in
displaying both text elements.
#include <iostream.h>
#include <ospace/web.h>
int main()
{
os_page page( "Find#1 Example" );
os_text hello( "Hello world!" );
hello.key( "mykey" );
page << hello << os_break();
os_element* found = page.find_first( "mykey" );
if ( found )
page << *found << os_break();
cout << page;
return 0;
}

Use the function find_all()
to find all occurrences of a key and return a
vector of os_element pointers. If no matching
elements are found, find_all() returns an empty
list.
In the following example a new
text element, named how , is added to the Web page
page in the previous example. The same key, mykey ,
is given to this new element. When the function find_all()
is called, it iterates through the page and streams each element back to the
page. This results in displaying both text elements.
#include <iostream.h>
#include <ospace/web.h>
int main()
{
os_page page( "Find#2 Example" );
os_text hello( "Hello world!" );
hello.key( "mykey" );
os_text how( "How are you?!" );
how.key( "mykey" );
page << hello << os_break()
<< how << os_break();
vector< os_element* > found = page.find_all( "mykey" );
vector< os_element* >::iterator it;
for ( it = found.begin(); it != found.end(); it++ )
page << **it << os_break();
cout << page;
return 0;
}

Copyright©1994-2026 Recursion
Software LLC
All Rights Reserved - For use by licensed users only.