Generics Reference Manual

Generics Tools

    Generics defines some useful tools. Part of them are template declarations. The main ones are the TBuffer <T> and TNode <T> definitions. It won't be entirely listed in this document but you are invited to read the nservices.h file for complete comments. All the templates are defined in a name space called NServices.

    The Generics CString class is defined on the TBuffer <T> services. Let's just see some code sample facilities on strings :

    CString str1 ("Generics");
    CString str2 ("true");
    CString str3 (26L);
    CString str4 ("-48");
    CString str5 ("a string | to cut | with a specified | field separator");

    str1 += CString (" defines some useful tools");
    str1.Substitute (CString("tools"), CString("services"));

    printf ("%s", str1.Get());          // "Generics defines some useful services"
    printf ("%d", str2.ToBool());   // "1"
    printf ("%s", str3.Get());          // "26"
    printf ("%d", str4.ToLong());  // ''-48"

    CStrings strtab (str5.Cut (CString("|")));
    for (size_t i=0; i<strtab.GetLength(); i++) printf ("%s\n", strtab[i] -> Get());
                                                                        // a string
                                                                        // to cut
                                                                        // with a specified
                                                                        //field separator