Example #1
0
TTErr TTEnvironment::registerClass(const TTSymbolPtr className, const TTString& tagString, const TTObjectInstantiationMethod anInstantiationMethod)
{
	TTValue		v((TTString&)tagString);	// The tags to be associated with the class we are registering.
	TTValue		tagObjects;					// Contains a TTList of objects in the environment with the given tag.
	TTClassPtr	theClass;
	TTErr		err;
	TTList*		classNamesForTag;			// The TTList contained by tagObjects
	TTUInt16	size;
	TTSymbolPtr	tag;
	TTValue		result;

	err = classes->lookup(className, result);
	
	// If a class is already registered with this name, then we do not want to register another class with the same name!
	if (err == kTTErrValueNotFound) {
		
		// 1. Turn the string into an array of symbols
		v.transformCSVStringToSymbolArray();
		
		// 2. Create the class and associate it with its name
		theClass = new TTClass(className, v, anInstantiationMethod);
		
		// 3. For each symbol in the TTValue array...
		size = v.getSize();
		for (TTUInt16 i=0; i<size; i++) {
			v.get(i, &tag);
			
			// 4. Look to see if this tag exists yet
			err = tags->lookup(tag, tagObjects);
			if (!err) {
				classNamesForTag = (TTList*)(TTPtr(tagObjects));
				
				// TODO: The following code demonstrates so extreme lameness that we need to evaluate.
				//	First, we should probably just do this section of code with TTValue instead of TTList (but we needed code to test TTList)
				//	Second, TTList is taking references but keeping things internally as pointers, which leads to lots of confusion
				//	Third, we have to pass objects that are permanent - so no temporaries are allowed unless we make TTList do a copy
				//	etc.

				// TODO: We need to factor out a function to add a tag for a named class (or a given class ptr)
				
				//classNamesForTag->append(className);
				classNamesForTag->append(*new TTValue(className));
			}
			else {
				classNamesForTag = new TTList;
				tagObjects = TTPtr(classNamesForTag);
				tags->append(tag ,tagObjects);
				classNamesForTag->append(*new TTValue(className));
			}
		}	
		
		// 4. Register it
		err = registerClass(theClass);
	}
	return err;
}
Example #2
0
TTErr TTHash::getKeysSorted(TTValue& hashKeysSorted, TTBoolean(comparisonFunction)(TTValue&, TTValue&))
{
	lock();
	TTList		listToSort;
	TTValue		v;
	TTSymbol	key;
	
	// fill a list to sort
	for (TTHashMapIter iter = HASHMAP->begin(); iter != HASHMAP->end(); iter++) {
		TTPtrSizedInt	a = iter->first;
		TTSymbol		b((TTSymbolBase*)a);
		
		if (comparisonFunction) {
			v = b;	// the key
			v.append(TTPtr(iter->second));	// a pointer to the stored value
			listToSort.append(v);
		}
		else
			listToSort.append(b);
	}
	
	listToSort.sort(comparisonFunction);
	
	// fill the result
	hashKeysSorted.clear();
	for (listToSort.begin(); listToSort.end(); listToSort.next()) {
		
		if (comparisonFunction) {
			key = listToSort.current()[0];
			hashKeysSorted.append(key);
		}
		else
			hashKeysSorted.append(listToSort.current());
	}
	
	unlock();
	return kTTErrNone;
}