CTTL on
SourceForge |
Download
Latest |
Documentation
Index |
Library
News |
CVS
Repository |
Other
Links |
Rudimentary program that demonstrates concept of offset identity, the CTTL equivalent of a logical offset.
// sample program: input.cpp // demonstrates concept of offset identities //#define NDEBUG // define to stop assertions from being compiled #include <cassert> #include <iostream> #include "cttl/cttl.h" int main() { using namespace cttl; // create input object with identity vector size == 6 input<> inp( "one two three", 6 ); // create nodes node<> n0( inp, 0 ); node<> n1( inp, 1 ); node<> n2( inp, 2 ); node<> n3( inp, 3 ); node<> n4( inp, 4 ); node<> n5( inp, 5 ); // create edges edge<> e01( n0, n1 ); const_edge<> e23( n2, n3 ); const_edge<> e45( n4, n5 ); // pretend that we parsed the input: n0.offset( 0 ); n1.offset( 3 ); n2.offset( 4 ); n3.offset( 7 ); n4.offset( 8 ); n5.offset( 13 ); // verify that edges correctly point to the substrings: assert( e01.text() == "one" ); assert( e23.text() == "two" ); assert( e45.text() == "three" ); // delete first substring: e01.text( "" ); // verify new substrings: assert( e01.text() == "" ); assert( e23.text() == "two" ); assert( e45.text() == "three" ); // verify new absolute offsets: assert( n0.offset() == 0 ); assert( n1.offset() == 0 ); assert( n2.offset() == 1 ); assert( n3.offset() == 4 ); assert( n4.offset() == 5 ); assert( n5.offset() == 10 ); // verify modified input text: assert( inp.text() == " two three" ); return 0; }
Permission to copy, use, modify, sell and distribute this document is granted provided this copyright notice appears in all copies. This document is provided "as is" without express or implied warranty, and with no claim as to its suitability for any purpose.