<<< Alias for STL sequence | Lambda Home | Alias for std::map >>> |
Common Text Transformation Library http://cttl.sourceforge.net/
Keywords: node_edge_alias.cpp, node, edge, alias::identity, alias::line, alias::insert_go, alias::insert_stay, alias::text, alias::length, alias::text_toupper, alias::text_swap
// node_edge_alias.cpp // Program illustrates access to cttl::node and cttl::edge // via alias helper functions. #define CTTL_TRACE_RULES // automatically turns lambda tracing on #include "cttl/cttl.h" #include "lambda/lambda.h" using namespace cttl; int main(/*int argc, char* argv[]*/) { std::string inp = "hello!"; edge<> inp_substr( inp ); lambda< edge<> >::scalar_reference substring( &inp_substr ); lambda< node<> >::scalar_reference inp_first( &inp_substr.first ); lambda< node<> >::scalar_reference inp_second( &inp_substr.second ); ( CTTL_LAMBDA_ASSERT( alias::identity( inp_first, substring.top().second ) != 0 ) ).evaluate(); // line ( CTTL_LAMBDA_ASSERT( alias::line( inp_first ) == scalar( size_t( 1 ) ) ) ).evaluate(); // node::insert_go, insert_stay ( alias::insert_go( &inp_second, std::string( "one" ) ), alias::insert_stay( &inp_second, std::string( "two" ) ) ).evaluate(); ( CTTL_LAMBDA_ASSERT( alias::text( substring ) == scalar( std::string( "hello!one" ) ) ) ).evaluate(); // length ( CTTL_LAMBDA_ASSERT( scalar( std::string( "hello!one" ).length() ) == alias::length( substring ) ) ).evaluate(); // text_toupper ( alias::text_toupper( &substring ) ).evaluate(); ( CTTL_LAMBDA_ASSERT( alias::text( substring ) == scalar( std::string( "HELLO!ONE" ) ) ) ).evaluate(); // text_swap edge<> edge_tail = inp_substr; ( alias::text_swap( &substring, &edge_tail ) ).evaluate(); ( CTTL_LAMBDA_ASSERT( scalar( std::string( "HELLO!ONE" ) ) == alias::text( scalar( &edge_tail ) ) ) ).evaluate(); return 0; }
Keywords: node_2_character_access.cpp, overloaded subscript operator, alias::offset, const_scalar
// node_2_character_access.cpp // Program demonstrates overloaded subscript operators. // Subscript access to characters of std::string via cttl::node operator[]. #include "cttl/cttl.h" #include "lambda/lambda.h" using namespace cttl; int main() { std::string inp = "abcdef"; node<> node1( inp ); node<> node2 = node1; lambda< char >::scalar ch; lambda< node<> >::scalar n1( node1 ); lambda< node<> >::scalar n2( node2 ); ( // update node positions: alias::offset( &n1, size_t( 0 ) ), alias::offset( &n2, size_t( 1 ) ), // swap characters: ch = n1[ const_scalar( 0 ) ], n1[ const_scalar( 0 ) ] = n2[ scalar( 0 ) ], n2[ const_scalar( 0 ) ] = ch ).evaluate(); assert( inp == "bacdef" ); }
Keywords: alias_text.cpp, alias::text, string manipulation, alias::basic_string::push_back, alias::append, alias::assign, alias::length
// alias_text.cpp // Program demonstrates alias::text() helper and std::string manipulation. #define CTTL_TRACE_RULES // automatically turns lambda tracing on #include "cttl/cttl.h" #include "lambda/lambda.h" using namespace cttl; int main(/*int argc, char* argv[]*/) { std::string inp = "hello"; edge<> inp_substr( inp ); lambda< edge<> >::scalar_reference substring( &inp_substr ); lambda< std::string >::scalar str; // text, write ( alias::text( &substring, std::string( "bye" ) ) ).evaluate(); // text, read ( str = alias::text( substring ) ).evaluate(); ( CTTL_LAMBDA_ASSERT( str == scalar( std::string( "bye" ) ) ) ).evaluate(); assert( inp == "bye" ); // basic_string push_back ( alias::basic_string::push_back( &str, 'X' ) ).evaluate(); ( CTTL_LAMBDA_ASSERT( str == scalar( std::string( "byeX" ) ) ) ).evaluate(); // append ( alias::append( &str, std::string( "YZ" ) ) ).evaluate(); ( CTTL_LAMBDA_ASSERT( str == scalar( std::string( "byeXYZ" ) ) ) ).evaluate(); // assign ( alias::assign( &str, std::string( "hi" ) ) ).evaluate(); ( CTTL_LAMBDA_ASSERT( str == scalar( std::string( "hi" ) ) ) ).evaluate(); // compare ( CTTL_LAMBDA_ASSERT( !alias::compare( str, std::string( "hi" ) ) ) ).evaluate(); // length ( CTTL_LAMBDA_ASSERT( scalar( std::string( "hi" ).length() ) == alias::length( str ) ) ).evaluate(); return 0; }
Copyright © 1997-2009 Igor Kholodov mailto:cttl@users.sourceforge.net.
Permission to copy 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.
<<< Alias for STL sequence | Lambda Home | Alias for std::map >>> |