Prior to V18, Open C++ included template classes for character strings (UgString) and dynamic arrays (UgArray). Both were used as input and output from various Open C++ methods. These classes were very similar to the std::string and std::vector classes in the C++ Standard Template Library (STL). In V18, the STL classes std::vector and std::string replaced and obsoleted UgArray and UgString , respectively.
New code written against V18 libraries is advised to use the STL classes directly. The header files ug_vector.hxx and ug_string.hxx have been provided as platform-independent methods of including the STL header files that define std::vector and std::string , respectively.
Old code currently using UgArray or UgString must be modified to compile, link, and run using V18 libraries. We provide the following steps:
typedef UgString std::string;
#define UgArray std::vector
// Initialize the pMyPart pointer
// Get the description string for this part
// Make sure it isn't a null string
if (!description.empty ( ))
??? // do something with it
You can also get a C-style pointer to a character array from a std::string object for compatibility with C functions. If description is still a std::string object from the above example, then:
printf( "Description = %s/n", description.c_str() );
It is important to remember that the C-style pointer from a std::string object must be considered a const pointer; you should not modify the string via the C-style pointer.
You will normally use the UgIterator class to cycle through all the NX objects of a given class.
// Construct an iterator for NX face objects
UgIterator <UgFace *> curFace;
// Loop through all faces
while (!curFace->isFinished ())
??? // Get the name of the current face
??? std::string faceName=(*curFace)->getName();
Note that there are three steps involved in iterating over all objects of a given type:
Construct an UgIterator object. UgIterator is a template class, which means that it is a generic class that can be used to iterate over many different types of NX classes. You identify the specific NX class when you construct the UgIterator object, as in < UgFace * > above. The class must be instantiable. In fact, you will get a compiler error if you try to construct a UgIterator object on a base class such as UgConicObject. The UgIterator constructor also has an optional argument (not used in the above example) that allows you to iterate over objects in a part other than the current work part.
You can similarly use the UgIterator class to find all the NX parts loaded in your current session.
// Construct an iterator for NX part objects
UgIterator <UgPart *> curPart;
// Loop through all loaded parts
??? // Close this part if it is not metric
??? if (!(*curPart)->isMillimeters ())
??????? (*curPart)->close ( true );