<commit_before>/** @file
 *
 * @ingroup modularLibrary
 *
 * @brief A Mirror Object
 *
 * @details
 *
 * @authors <NAME>
 *
 * @copyright © 2010, <NAME> @n
 * This code is licensed under the terms of the "New BSD License" @n
 * http://creativecommons.org/licenses/BSD/
 */


#include "TTMirror.h"

#define thisTTClass			TTMirror
#define thisTTClassName		"Mirror"
#define thisTTClassTags		"mirror"

TT_MODULAR_CONSTRUCTOR,
mType(kTTSymEmpty),
mGetAttributeCallback(NULL),
mSetAttributeCallback(NULL),
mSendMessageCallback(NULL),
mListenAttributeCallback(NULL)
{	
	TTValue				attributeNames, messageNames, args;
	TTSymbol			name;
	TTAttributePtr		anAttribute;
	TTAttributeFlags	attributeFlags = kTTAttrPassObject;
	TTMessagePtr		aMessage;
	
	TT_ASSERT("Correct number of args to create TTMirror", arguments.size() == 5);
    
	if (arguments.size() >= 1)
		mType = arguments[0];
    
    if (mType != kTTSymEmpty) {
        
        if (arguments.size() >= 2)
            mGetAttributeCallback = TTCallbackPtr((TTObjectBasePtr)arguments[1]);
        
        if (arguments.size() >= 3)
            mSetAttributeCallback = TTCallbackPtr((TTObjectBasePtr)arguments[2]);
        
        if (arguments.size() >= 4)
            mSendMessageCallback = TTCallbackPtr((TTObjectBasePtr)arguments[3]);
        
        if (arguments.size() >= 5)
            mListenAttributeCallback = TTCallbackPtr((TTObjectBasePtr)arguments[4]);
        
        
        // instantiate a temp object to copy visible attributes and messages
        TTObjectBasePtr anObject = NULL;
        args.resize(32);
        TTObjectBaseInstantiate(mType,  &anObject, args);
        
        anObject->getAttributeNames(attributeNames);
        for (TTUInt32 i = 0; i < attributeNames.size(); i++) {
            
            anAttribute = NULL;
            name = attributeNames[i];
            anObject->getAttribute(name, &anAttribute);
            
            if (mGetAttributeCallback)
                addMirrorAttribute(name, anAttribute->type);
            
            // else cache the attribute value
            else {
                
                addMirrorCachedAttribute(name, anAttribute->type);
                
                mAttributeValueCache.append(name, kTTValNONE);
            }
            
            setAttributeGetterFlags(name, attributeFlags);
            setAttributeSetterFlags(name, attributeFlags);
            
            // TODO : addMirrorAttributeProperty
            //addMirrorAttributeProperty(name, readOnly, anAttribute->readOnly);
        }
        
        anObject->getMessageNames(messageNames);
        for (TTUInt32 i = 0; i < messageNames.size(); i++) {
            
            name = messageNames[i];
            anObject->getMessage(name, &aMessage);
            
            addMirrorMessage(name, aMessage->flags);
            
            // TODO : addMirrorMessageProperty
        }
        
        TTObjectBaseRelease(&anObject);<commit_msg>Testing if the object exist before to copy attributes<commit_after>/** @file
 *
 * @ingroup modularLibrary
 *
 * @brief A Mirror Object
 *
 * @details
 *
 * @authors <NAME>
 *
 * @copyright © 2010, <NAME> @n
 * This code is licensed under the terms of the "New BSD License" @n
 * http://creativecommons.org/licenses/BSD/
 */


#include "TTMirror.h"

#define thisTTClass			TTMirror
#define thisTTClassName		"Mirror"
#define thisTTClassTags		"mirror"

TT_MODULAR_CONSTRUCTOR,
mType(kTTSymEmpty),
mGetAttributeCallback(NULL),
mSetAttributeCallback(NULL),
mSendMessageCallback(NULL),
mListenAttributeCallback(NULL)
{	
	TTValue				attributeNames, messageNames, args;
	TTSymbol			name;
	TTAttributePtr		anAttribute;
	TTAttributeFlags	attributeFlags = kTTAttrPassObject;
	TTMessagePtr		aMessage;
    TTErr               err;
	
	TT_ASSERT("Correct number of args to create TTMirror", arguments.size() == 5);
    
	if (arguments.size() >= 1)
		mType = arguments[0];
    
    if (mType != kTTSymEmpty) {
        
        if (arguments.size() >= 2)
            mGetAttributeCallback = TTCallbackPtr((TTObjectBasePtr)arguments[1]);
        
        if (arguments.size() >= 3)
            mSetAttributeCallback = TTCallbackPtr((TTObjectBasePtr)arguments[2]);
        
        if (arguments.size() >= 4)
            mSendMessageCallback = TTCallbackPtr((TTObjectBasePtr)arguments[3]);
        
        if (arguments.size() >= 5)
            mListenAttributeCallback = TTCallbackPtr((TTObjectBasePtr)arguments[4]);
        
        
        // instantiate a temp object to copy visible attributes and messages
        TTObjectBasePtr anObject = NULL;
        args.resize(32);
        err = TTObjectBaseInstantiate(mType,  &anObject, args);
        
        if (!err) {
            
            anObject->getAttributeNames(attributeNames);
            for (TTUInt32 i = 0; i < attributeNames.size(); i++) {
                
                anAttribute = NULL;
                name = attributeNames[i];
                anObject->getAttribute(name, &anAttribute);
                
                if (mGetAttributeCallback)
                    addMirrorAttribute(name, anAttribute->type);
                
                // else cache the attribute value
                else {
                    
                    addMirrorCachedAttribute(name, anAttribute->type);
                    
                    mAttributeValueCache.append(name, kTTValNONE);
                }
                
                setAttributeGetterFlags(name, attributeFlags);
                setAttributeSetterFlags(name, attributeFlags);
                
                // TODO : addMirrorAttributeProperty
                //addMirrorAttributeProperty(name, readOnly, anAttribute->readOnly);
            }
            
            anObject->getMessageNames(messageNames);
            for (TTUInt32 i = 0; i < messageNames.size(); i++) {
                
                name = messageNames[i];
                anObject->getMessage(name, &aMessage);
                
                addMirrorMessage(name, aMessage->flags);
                
                // TODO : addMirrorMessageProperty
            }
            
            TTObjectBaseRelease(&anObject);
        }
{'fraction_non_alphanumeric': 0.09619722848855945, 'fraction_numerical': 0.007412181759587496, 'mean_word_length': 2.0189688715953307, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '116443', 'n_tokens_mistral': 1746, 'n_tokens_neox': 1649, 'n_words': 348}