os_element


The basic unit of page composition.

An os_element is the basic unit of page composition and serves as the base class for all Web page entities. It is unnecessary in most cases to create an os_element explicitly, because os_element -derived classes are typically created instead.

An os_element consists of an HTML tag, zero or more attributes, and an optional end tag. Only the end tag presence is specified, and its contents are constructed automatically by preceding the specified tag with a slash (/). The tag and end tag are specified in a constructor and can be queried through the tag() and end_tag() member functions. Attributes are set through set_attribute() , cleared through clear_attribute() , and queried through get_attribute() , get_attribute_as_int() , and attribute_exists() member functions.

An element can be assigned a key that:

By default, the element key is set to an empty string.

When an os_element is placed in a collection, such as os_page or os_table , the key allows the os_element to be located, modified, replaced, or deleted. The key is specified through the key() member function.

Declaration

#include <ospace/web/element.h>
class os_element

Interface

Constructor
os_element()
Constructs an element with an empty HTML tag and no end tag.
Constructor
os_element( const string& tag , bool end_tag )
Constructs an element with HTML tag tag and an end tag according to end_tag (default true ).
Constructor
os_element( const os_element& rhs )
Constructs an element that is a copy of rhs .
Destructor
virtual ~os_element()
Destroys the element.
!=
bool operator!=( const os_element& rhs )
Returns true if element key is not equal to rhs key.
!=
bool operator!=( const string& key )
Returns true if element key is not equal to key .
=
os_element& operator=( const os_element& rhs )
Replaces the element contents with a copy of rhs and returns a reference to the element.
==
bool operator==( const string& key )
Returns true if element key is equal to key .
==
bool operator==( const os_element& rhs )
Returns true if element key is equal to rhs key.
attribute_exists
bool attribute_exists( const string& attribute ) const
Returns true if a value has been set for attribute attribute .
clear_attribute
void clear_attribute( const string& attribute )
Clears attribute attribute .
clone
virtual os_element* clone() const
Returns a base class pointer to a heap-based deep copy of the element.
end_tag
bool end_tag() const
Returns true if the element has an end tag.
get_attribute
string get_attribute( const string& attribute ) const
Returns the value of attribute attribute , or the empty string if attribute is not set.
get_attribute_as_int

int get_attribute_as_int( const string& attribute ) const
Returns the value of attribute attribute converted to an int, or 0 if attribute is not set.
key
void key( const string& key )
Sets the key to key .
key
string key() const
Returns the key.
print
virtual void print( ostream& os ) const
Prints the HTML tag, all attributes, and the end tag (if one exists) to os .
print_end
void print_end( ostream& os ) const
Prints the end tag (if the element has one) to os .
print_start
void print_start( ostream& os ) const
Prints the HTML tag and all attributes to os .
set_attribute
void set_attribute( const string& attribute , const string& value )
Sets the attribute attribute to value value .
set_attribute
void set_attribute( const string& attribute , int value )
Sets the attribute attribute to the string representation of value .
tag
string tag() const
Returns the HTML tag.

Non-Member Functions

<<
ostream& operator<<( ostream& os , const os_element& element )
Prints the element element in HTML format to os and returns a reference to os .

Copyright©1994-2026 Recursion Software LLC
All Rights Reserved