<commit_before>/** @file
 *
 * @ingroup foundationLibrary
 *
 * @brief Provides a common way of representing composite values.
 *
 * @details #TTValue is the primary interface used to pass values to and from methods in Jamoma Core. Methods for a given #TTObject should be passed both an input and output value to complete its operation, while the return is reserved for a #TTErr.
 @n@n Each #TTValue may be composed of a single element or many elements because it has been defined as a subclass of the C++ standard library's <a href="http://www.cplusplus.com/reference/vector/vector/">vector class</a>. This also enables our class to inherit familiar functions such as size() and from its parent class.
 @n@n Individual items within the #TTValue are defined by the #TTElement class. These individual elements may be one of the defined types in the #TTDataType enumeration.
 *
 * @authors <NAME>, <NAME>, <NAME>, <NAME>, <NAME>, <NAME>
 *
 * @copyright Copyright © 2008, <NAME> @n
 * This code is licensed under the terms of the "New BSD License" @n
 * http://creativecommons.org/licenses/BSD/
 */


#ifndef __TT_VALUE_H__
#define __TT_VALUE_H__

#include "TTElement.h"
#include <functional>


/**	@copybrief TTValue.h
	@copydetails TTValue.h
*/
class TTValue : public TTElementVector {
    
public:

	/** @brief Constructor for an empty value */
	TTValue()
	{
		reserve(1);
	}
	
	/** @brief Constructor with a single initial element. */
	template<class T>
	TTValue(const T& anInitialValue)
	{
		resize(1);
		at(0) = anInitialValue;
	}
		
	/** @brief Constructor with two initial elements. */
	template <class T, class U>
	TTValue(const T& aFirstElementInitialValue, const U& aSecondElementInitialValue)
	{
		resize(2);
		at(0) = aFirstElementInitialValue;
		at(1) = aSecondElementInitialValue;
	}
	
	/** @brief Constructor with three initial elements. */
	template <class T, class U, class V>
	TTValue(const T& aFirstElementInitialValue, const U& aSecondElementInitialValue, const V& aThirdElementInitialValue)
	{
		resize(3);
		at(0) = aFirstElementInitialValue;
		at(1) = aSecondElementInitialValue;
		at(2) = aThirdElementInitialValue;
	}

	/** @brief Constructor with four initial elements. */
	template <class T, class U, class V, class W>
	TTValue(const T& aFirstElementInitialValue, const U& aSecondElementInitialValue, const V& aThirdElementInitialValue, const W& aFourthElementInitialValue)
	{
		resize(4);
		at(0) = aFirstElementInitialValue;
		at(1) = aSecondElementInitialValue;
		at(2) = aThirdElementInitialValue;
		at(3) = aFourthElementInitialValue;
	}

	// force the destructor to be non-virtual
	// we don't want subclasses of TTValue so it won't be a problem, and this solves linking snafus in some edge cases
    /** @brief Destructor */
	~TTValue()
	{;}
	
    
private:
	/** @brief Internal method used by the constructors. */
	void init();
	
	/** @brief Performs a deep copy of the object */
	inline void copy(const TTValue& obj);


public:

    /** @brief Clear all values from the vector, leaving with size of 0 */
	void clear() {
		TTElementVector::clear();
	}

    
	/** @brief Copy a value starting from an index until another index */
	void copyRange(const TTValue& obj, TTUInt16 startIndex, TTUInt16 endIndex)
	{
		resize(endIndex - startIndex);
		for (size_t i=0; i<size(); i++)
			at(i) = obj[startIndex+i];
	}
	
	
	/** @brief Copy a value starting from an index until the last element */
	void copyFrom(const TTValue& obj, TTUInt16 index)
	{
		copyRange(obj, index, obj.size());
	}
	
	
	/** @brief Insert another TTValue before the first element.
     @details
     The following example code would result in TTValue b having elements ordered <1, 2, 3, ga, bu, zo, meu>:
     @code{.cpp}
     TTValue a(1, 2, 3); 
     TTValue b(ga, bu, zo, meu);
     b.prepend(a);
     @endcode
	 */
	void prepend(const TTValue& aValueToPrepend)
	{
		TTValue v = aValueToPrepend;

		v.append(*this);
		*this = v;
	}

	
	/**	@brief Assign a value to TTValue.
     @details Overwrites current elements.
     */
	template<class T>
	TTValue& operator = (T value)
	{
		resize(1);
		at(0) = value;
		return *this;
	}
	
	/**	@brief Test equality of two values */
	friend bool operator == (const TTValue& a, const TTValue& b)
	{
		if (a.size() == b.size()) {
			for (size_t i=0; i<a.size(); i++) {
				if (a.at(i) != b.at(i)) {
					return false;
				}
			}
			return true;
		}
		return false;
	}

#ifndef TT_PLATFORM_WIN
    /** @overload
     */
	template<class T>
	friend bool operator == (const TTValue& a, const T b)
	{
		if (a.size() == 1 && a[0] == b)
			return true;
		else
			return false;
	}
#endif

	/** @brief Get a value from TTValue */
	template<class T>
	operator T() const
	{
		if (size())
			return T(at(0));
		else
			return T(0);
	}

    // TTSymbol needs to be manually wrapped to avoid ambiguity as interpretted by the clang compiler
    /** @overload
     */
	operator TTSymbol() const
	{
		if (size())
			return at(0);
		else
			return kTTSymEmpty;
	}
	
    /** @brief Insert a single TTElement at the end */
	template<class T>
	void append(const T& anElementValueToAppend)<commit_msg>get value from TTValue for TTObject case too<commit_after>/** @file
 *
 * @ingroup foundationLibrary
 *
 * @brief Provides a common way of representing composite values.
 *
 * @details #TTValue is the primary interface used to pass values to and from methods in Jamoma Core. Methods for a given #TTObject should be passed both an input and output value to complete its operation, while the return is reserved for a #TTErr.
 @n@n Each #TTValue may be composed of a single element or many elements because it has been defined as a subclass of the C++ standard library's <a href="http://www.cplusplus.com/reference/vector/vector/">vector class</a>. This also enables our class to inherit familiar functions such as size() and from its parent class.
 @n@n Individual items within the #TTValue are defined by the #TTElement class. These individual elements may be one of the defined types in the #TTDataType enumeration.
 *
 * @authors <NAME>, <NAME>, <NAME>, <NAME>, <NAME>, <NAME>
 *
 * @copyright Copyright © 2008, <NAME> @n
 * This code is licensed under the terms of the "New BSD License" @n
 * http://creativecommons.org/licenses/BSD/
 */


#ifndef __TT_VALUE_H__
#define __TT_VALUE_H__

#include "TTElement.h"
#include <functional>


/**	@copybrief TTValue.h
	@copydetails TTValue.h
*/
class TTValue : public TTElementVector {
    
public:

	/** @brief Constructor for an empty value */
	TTValue()
	{
		reserve(1);
	}
	
	/** @brief Constructor with a single initial element. */
	template<class T>
	TTValue(const T& anInitialValue)
	{
		resize(1);
		at(0) = anInitialValue;
	}
		
	/** @brief Constructor with two initial elements. */
	template <class T, class U>
	TTValue(const T& aFirstElementInitialValue, const U& aSecondElementInitialValue)
	{
		resize(2);
		at(0) = aFirstElementInitialValue;
		at(1) = aSecondElementInitialValue;
	}
	
	/** @brief Constructor with three initial elements. */
	template <class T, class U, class V>
	TTValue(const T& aFirstElementInitialValue, const U& aSecondElementInitialValue, const V& aThirdElementInitialValue)
	{
		resize(3);
		at(0) = aFirstElementInitialValue;
		at(1) = aSecondElementInitialValue;
		at(2) = aThirdElementInitialValue;
	}

	/** @brief Constructor with four initial elements. */
	template <class T, class U, class V, class W>
	TTValue(const T& aFirstElementInitialValue, const U& aSecondElementInitialValue, const V& aThirdElementInitialValue, const W& aFourthElementInitialValue)
	{
		resize(4);
		at(0) = aFirstElementInitialValue;
		at(1) = aSecondElementInitialValue;
		at(2) = aThirdElementInitialValue;
		at(3) = aFourthElementInitialValue;
	}

	// force the destructor to be non-virtual
	// we don't want subclasses of TTValue so it won't be a problem, and this solves linking snafus in some edge cases
    /** @brief Destructor */
	~TTValue()
	{;}
	
    
private:
	/** @brief Internal method used by the constructors. */
	void init();
	
	/** @brief Performs a deep copy of the object */
	inline void copy(const TTValue& obj);


public:

    /** @brief Clear all values from the vector, leaving with size of 0 */
	void clear() {
		TTElementVector::clear();
	}

    
	/** @brief Copy a value starting from an index until another index */
	void copyRange(const TTValue& obj, TTUInt16 startIndex, TTUInt16 endIndex)
	{
		resize(endIndex - startIndex);
		for (size_t i=0; i<size(); i++)
			at(i) = obj[startIndex+i];
	}
	
	
	/** @brief Copy a value starting from an index until the last element */
	void copyFrom(const TTValue& obj, TTUInt16 index)
	{
		copyRange(obj, index, obj.size());
	}
	
	
	/** @brief Insert another TTValue before the first element.
     @details
     The following example code would result in TTValue b having elements ordered <1, 2, 3, ga, bu, zo, meu>:
     @code{.cpp}
     TTValue a(1, 2, 3); 
     TTValue b(ga, bu, zo, meu);
     b.prepend(a);
     @endcode
	 */
	void prepend(const TTValue& aValueToPrepend)
	{
		TTValue v = aValueToPrepend;

		v.append(*this);
		*this = v;
	}

	
	/**	@brief Assign a value to TTValue.
     @details Overwrites current elements.
     */
	template<class T>
	TTValue& operator = (T value)
	{
		resize(1);
		at(0) = value;
		return *this;
	}
	
	/**	@brief Test equality of two values */
	friend bool operator == (const TTValue& a, const TTValue& b)
	{
		if (a.size() == b.size()) {
			for (size_t i=0; i<a.size(); i++) {
				if (a.at(i) != b.at(i)) {
					return false;
				}
			}
			return true;
		}
		return false;
	}

#ifndef TT_PLATFORM_WIN
    /** @overload
     */
	template<class T>
	friend bool operator == (const TTValue& a, const T b)
	{
		if (a.size() == 1 && a[0] == b)
			return true;
		else
			return false;
	}
#endif

	/** @brief Get a value from TTValue */
	template<class T>
	operator T() const
	{
		if (size())
			return T(at(0));
		else
			return T(0);
	}

    // TTSymbol needs to be manually wrapped to avoid ambiguity as interpretted by the clang compiler
    /** @overload
     */
	operator TTSymbol() const
	{
		if (size())
			return at(0);
		else
			return kTTSymEmpty;
	}
    
    // TTObject needs to be manually wrapped to avoid ambiguity as interpretted by the clang compiler
    /** @overload
     */
	operator TTObject() const
	{
		if (size())
			return at(0);
		else
			return TTObject();
	}
	
    /** @brief Insert a single TTElement at the end */
	template<class T>
	void append(const T& anElementValueToAppend)
{'fraction_non_alphanumeric': 0.11495567629396626, 'fraction_numerical': 0.007911543227528357, 'mean_word_length': 3.514629948364888, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5756203', 'n_tokens_mistral': 3701, 'n_tokens_neox': 3367, 'n_words': 1204}