<commit_before>/* 
 * A Receiver Object
 * Copyright © 2010, <NAME>
 * 
 * License: This code is licensed under the terms of the "New BSD License"
 * http://creativecommons.org/licenses/BSD/
 */

#include "TTReceiver.h"

#define thisTTClass			TTReceiver
#define thisTTClassName		"Receiver"
#define thisTTClassTags		"node, receiver"

TT_MODULAR_CONSTRUCTOR,

mAddress(kTTAdrsEmpty),
mEnable(YES),
mDirectory(NULL),
mReturnAddressCallback(NULL),
mReturnValueCallback(NULL),
mObserver(NULL),
mNodesObserversCache(NULL)
{
	TTNodeAddressPtr anAddress;
	
	TT_ASSERT("Correct number of args to create TTReceiver", arguments.getSize() == 3);
	
	if (arguments.getSize() >= 2)
		arguments.get(1, (TTPtr*)&mReturnAddressCallback);
	
	if (arguments.getSize() >= 3)
		arguments.get(2, (TTPtr*)&mReturnValueCallback);
	
	addAttributeWithSetter(Address, kTypeSymbol);
	addAttributeWithSetter(Enable, kTypeBoolean);
	
	addMessage(Get);
	addMessageProperty(Get, hidden, YES);
	
	mNodesObserversCache = new TTList();
	
	if (arguments.getSize() >= 1) {
		arguments.get(0, &anAddress);
		setAddress(anAddress);
	}
}

TTReceiver::~TTReceiver()
{
	unbind();
	
	if (mReturnAddressCallback) {
		delete (TTValuePtr)mReturnAddressCallback->getBaton();
		TTObjectRelease(TTObjectHandle(&mReturnAddressCallback));
	}
	
	if (mReturnValueCallback) {
		delete (TTValuePtr)mReturnValueCallback->getBaton();
		TTObjectRelease(TTObjectHandle(&mReturnValueCallback));
	}
}

TTErr TTReceiver::setAddress(const TTValue& newValue)
{
	unbind();
	newValue.get(0, &mAddress);
	
	if (mDirectory = getDirectoryFrom(mAddress)) {
		
		// default attribute to bind is value
		if (mAddress->getAttribute() == NO_ATTRIBUTE)
			mAddress = mAddress->appendAttribute(kTTSym_value);
		
		return bind();
	}
	else
		return kTTErrGeneric; ; // TODO : wait for directory
}

TTErr TTReceiver::setEnable(const TTValue& newValue)
{
	mEnable = newValue;
	
	return kTTErrNone;
}

#if 0
#pragma mark -
#pragma mark Some Methods
#endif

TTErr TTReceiver::Get()
{
	TTNodePtr	aNode;
	TTObjectPtr anObject;
	TTNodeAddressPtr anAddress;
	TTSymbolPtr	ttAttributeName;
	TTValue		data, v;
	TTErr		err;
	
	if (!mNodesObserversCache->isEmpty()) {
		
		ttAttributeName = ToTTName(mAddress->getAttribute());
		
		// for each node of the selection
		for (mNodesObserversCache->begin(); mNodesObserversCache->end(); mNodesObserversCache->next()) {
			
			// get a node from the selection
			mNodesObserversCache->current().get(0,(TTPtr*)&aNode);
			
			// get the value of the attribute
			if (anObject = aNode->getObject()) {
				
				err = anObject->getAttributeValue(ttAttributeName, data); 
				
				if (!err) {
					
					// output the address of the node (in case we use * inside the binded address)
					aNode->getAddress(&anAddress);
					anAddress = anAddress->appendAttribute(mAddress->getAttribute());
					
					// return the address
					v.append(anAddress);
					
					if (mReturnAddressCallback)
						mReturnAddressCallback->notify(v);
					
					// return the value
					if (mReturnValueCallback)
						mReturnValueCallback->notify(data);
				}
				else
					;// TODO : error "%s doesn't exist"
			}<commit_msg>Fixing TTReceive get method to return the good address when it binds on several address<commit_after>/* 
 * A Receiver Object
 * Copyright © 2010, <NAME>
 * 
 * License: This code is licensed under the terms of the "New BSD License"
 * http://creativecommons.org/licenses/BSD/
 */

#include "TTReceiver.h"

#define thisTTClass			TTReceiver
#define thisTTClassName		"Receiver"
#define thisTTClassTags		"node, receiver"

TT_MODULAR_CONSTRUCTOR,

mAddress(kTTAdrsEmpty),
mEnable(YES),
mDirectory(NULL),
mReturnAddressCallback(NULL),
mReturnValueCallback(NULL),
mObserver(NULL),
mNodesObserversCache(NULL)
{
	TTNodeAddressPtr anAddress;
	
	TT_ASSERT("Correct number of args to create TTReceiver", arguments.getSize() == 3);
	
	if (arguments.getSize() >= 2)
		arguments.get(1, (TTPtr*)&mReturnAddressCallback);
	
	if (arguments.getSize() >= 3)
		arguments.get(2, (TTPtr*)&mReturnValueCallback);
	
	addAttributeWithSetter(Address, kTypeSymbol);
	addAttributeWithSetter(Enable, kTypeBoolean);
	
	addMessage(Get);
	addMessageProperty(Get, hidden, YES);
	
	mNodesObserversCache = new TTList();
	
	if (arguments.getSize() >= 1) {
		arguments.get(0, &anAddress);
		setAddress(anAddress);
	}
}

TTReceiver::~TTReceiver()
{
	unbind();
	
	if (mReturnAddressCallback) {
		delete (TTValuePtr)mReturnAddressCallback->getBaton();
		TTObjectRelease(TTObjectHandle(&mReturnAddressCallback));
	}
	
	if (mReturnValueCallback) {
		delete (TTValuePtr)mReturnValueCallback->getBaton();
		TTObjectRelease(TTObjectHandle(&mReturnValueCallback));
	}
}

TTErr TTReceiver::setAddress(const TTValue& newValue)
{
	unbind();
	newValue.get(0, &mAddress);
	
	if (mDirectory = getDirectoryFrom(mAddress)) {
		
		// default attribute to bind is value
		if (mAddress->getAttribute() == NO_ATTRIBUTE)
			mAddress = mAddress->appendAttribute(kTTSym_value);
		
		return bind();
	}
	else
		return kTTErrGeneric; ; // TODO : wait for directory
}

TTErr TTReceiver::setEnable(const TTValue& newValue)
{
	mEnable = newValue;
	
	return kTTErrNone;
}

#if 0
#pragma mark -
#pragma mark Some Methods
#endif

TTErr TTReceiver::Get()
{
	TTNodePtr	aNode;
	TTObjectPtr anObject;
	TTNodeAddressPtr anAddress;
	TTSymbolPtr	ttAttributeName;
	TTValue		data, v;
	TTErr		err;
	
	if (!mNodesObserversCache->isEmpty()) {
		
		ttAttributeName = ToTTName(mAddress->getAttribute());
		
		// for each node of the selection
		for (mNodesObserversCache->begin(); mNodesObserversCache->end(); mNodesObserversCache->next()) {
			
			// get a node from the selection
			mNodesObserversCache->current().get(0,(TTPtr*)&aNode);
			
			// get the value of the attribute
			if (anObject = aNode->getObject()) {
				
				err = anObject->getAttributeValue(ttAttributeName, data); 
				
				if (!err) {
					
					// output the address of the node (in case we use * inside the binded address)
					aNode->getAddress(&anAddress);
					anAddress = anAddress->appendAttribute(mAddress->getAttribute());
					
					// return the address
					v.clear();
					v.append(anAddress);
					
					if (mReturnAddressCallback)
						mReturnAddressCallback->notify(v);
					
					// return the value
					if (mReturnValueCallback)
						mReturnValueCallback->notify(data);
				}
				else
					;// TODO : error "%s doesn't exist"
			}
{'fraction_non_alphanumeric': 0.12105098529871755, 'fraction_numerical': 0.004379105411323116, 'mean_word_length': 4.338063439065109, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 45, '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': '502081', 'n_tokens_mistral': 2388, 'n_tokens_neox': 2029, 'n_words': 465}