Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

hello_world.cpp


SourceForge.net Logo     CTTL on    
    SourceForge    
    Download    
    Latest    
    Documentation    
    Index    
    Library    
    News    
    CVS    
    Repository    
   Other    
   Links    

Template class cttl::input implements concept of the user input text. It instantiates a copy of std::basic_string and data structures that support substrings. The actual string type can be specified as a template parameter; the default type is std::string. The input object stores user text and becomes parent of all nodes and edges associated with this particular input. Template class cttl::node encapsulates the concept of a logical position inside the input. Internally, the node relies on the identity vector model. A pair of nodes defines cttl::edge, a template class that represents CTTL substrings.

The following program demonstrates interaction between instances of cttl input, node, and edge classes. The nodes insert text at their current positions. The edge objects are constructed from pairs of existing nodes. Edges encapsulate access to underlying substrings that program can access and modify:

// sample code: hello_world.cpp

#include <iostream>
#include "cttl/cttl.h"

int main()
{
    using cttl::input;
    using cttl::node;
    using cttl::edge;

    // at the beginning, input text is empty:
    input<> inp;

    // create chain of nodes for "hello, world!" as follows:
    //                            H    RSW    BE
    node<> H( new_node( inp ) );
    node<> R( new_node( inp ) );
    node<> S( new_node( inp ) );
    node<> W( new_node( inp ) );
    node<> B( new_node( inp ) );
    node<> E( new_node( inp ) );

    // construct edges from nodes
    edge<> hello( H, R );
    edge<> rest( R, S );
    edge<> space( S, W );
    edge<> world( W, B );
    edge<> exclaim( B, E );

    // assign text to edges:
    hello = "hello";
    rest = ",";
    space = " ";
    world = "world";
    exclaim = "!";

    // show results:
    std::cout << inp.text() << std::endl;
    std::cout << std::endl;

    // modify substrings:
    hello.first.insert_stay( "<GREETING>" );
    hello.second.insert_go( "</GREETING>" );
    rest = "<REST/>";
    space = "<WHITESPACE/>";
    world.first.insert_stay( "<SCOPE>" );
    world.second.insert_go( "</SCOPE>" );
    exclaim = "<EXCLAMATION/>";

    // show results:
    std::cout << hello.text() << std::endl;
    std::cout << rest.text() << std::endl;
    std::cout << space.text() << std::endl;
    std::cout << world.text() << std::endl;
    std::cout << exclaim.text() << std::endl;

    return 0;
}
This program displays the following output:
hello, world!

<GREETING>hello</GREETING>
<REST/>
<WHITESPACE/>
<SCOPE>world</SCOPE>
<EXCLAMATION/>



Copyright © 1997-2006 Igor Kholodov mailto:cttl@users.sourceforge.net.

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.


Generated on Thu Nov 2 17:44:54 2006 for Common Text Transformation Library by  doxygen 1.3.9.1