[SESI logo]

Houdini Development Toolkit - Version 6.5

Side Effects Software Inc. 2004

Utility Classes

UT_String Methods

The UT_String class is a general string class which we use extensively through the source. The important thing about the class is that it's aware of whether it owns the data or not.

There are several advantages to this. When the class is destructed, the data will be deleted if the class owns the data. If the class doesn't own the data, the data is left intact. When an operation is done on the class which requires a local copy of the data, the data is automatically hardened. By hardening, we mean that the reference to data is hard copied into a new buffer.

There are several methods which deal solely with ownership of the data.

  • harden()
    Makes a local copy of the string.
  • adopt(char *) Takes the argument and assumes ownership of the data. This means that when the UT_String is destructed, the data will be deleted as well.
  • steal(char *)
    This is a way to steal the contents of the UT_String. However, the class will still point to the data, however, when the class is destructed, the data will not be deleted.
  • Standard Operators

    Many standard operators are defined for the UT_String class. The full list can be found in the header file. However, in short, you can add to, compare, set etc. On a UT_String class. One of the nice things is that you don't have to worry about memory handling, the class should manage everything itself.

    Special Methods of Interest

  • parse(), parseInPlace(), tokenize() & tokenizeInPlace()
    These functions are really useful for quickly parsing a string into an argument list. parse differs from tokenize in that quoted strings are handled as single arguments. The InPlace methods will not harden the strings, so they can be used for lightweight parsing where you don't want to duplicate the whole string. For example:

    char buffer[256]; UT_String str(buffer); // Create string which references // the buffer while (is.getline(buffer)) { argc = str.parseInPlace(argv, maxargs); } In the above example, the string is simply used for parsing. The buffer gets replaced on every getline and so will be re-parsed. cshParse is a more complicated parser which takes a method to do variable expansion and one to do backquote expansion. cshParse uses the csh syntax to parse a string into its arguments.

  • save(), saveBinary(), load(), loadBinary()
    These methods will save strings to streams. If there are spaces in an ASCII string, it will automatically quote the string. Loading of the ASCII strings handles quoted strings. Binary strings are saved as a short (specifying the length of the string), followed by the text of the string.

  • match(), multiMatch(), contains()
    These methods will match a string against a search pattern. For example:

    UT_String str("geo1"); str.match("ge*"); // Returns 1 str.match("g?o?"); // Returns 1

  • Table of Contents
    Operators | Surface Operations | Particle Operations | Composite Operators | Channel Operators
    Material & Texture | Objects | Command and Expression | Render Output |
    Mantra Shaders | Utility Classes | Geometry Library | Image Library | Clip Library
    Customizing UI | Questions & Answers

    Copyright © 2004 Side Effects Software Inc.
    477 Richmond Street West, Toronto, Ontario, Canada M5V 3E7