<commit_before>//////////////////////////////////////////////////////////////////////////
//
//  Copyright (c) 2011-2012, <NAME>. All rights reserved.
//  Copyright (c) 2013, Image Engine Design Inc. All rights reserved.
//
//  Redistribution and use in source and binary forms, with or without
//  modification, are permitted provided that the following conditions are
//  met:
//
//      * Redistributions of source code must retain the above
//        copyright notice, this list of conditions and the following
//        disclaimer.
//
//      * Redistributions in binary form must reproduce the above
//        copyright notice, this list of conditions and the following
//        disclaimer in the documentation and/or other materials provided with
//        the distribution.
//
//      * Neither the name of <NAME> nor the names of
//        any other contributors to this software may be used to endorse or
//        promote products derived from this software without specific prior
//        written permission.
//
//  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
//  IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
//  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
//  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
//  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
//  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
//  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
//  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
//  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
//  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
//  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////

#ifndef GAFFER_VALUEPLUG_H
#define GAFFER_VALUEPLUG_H

#include "Gaffer/Plug.h"

#include "IECore/Object.h"

namespace Gaffer
{

IE_CORE_FORWARDDECLARE( DependencyNode )

/// The Plug base class defines the concept of a connection
/// point with direction. The ValuePlug class extends this concept
/// to allow the connections to pass values between connection
/// points, and for DependencyNode::compute() to be used to compute output
/// values.
class GAFFER_API ValuePlug : public Plug
{

	public :

		/// Constructs a ValuePlug which can be used as a parent for other ValuePlugs.
		ValuePlug( const std::string &name=defaultName<ValuePlug>(), Direction direction=In, unsigned flags=Default );
		~ValuePlug() override;

		GAFFER_PLUG_DECLARE_TYPE( Gaffer::ValuePlug, ValuePlugTypeId, Plug );

		bool acceptsChild( const GraphComponent *potentialChild ) const override;
		/// Accepts the input only if it is derived from ValuePlug.
		/// Derived classes may accept more types provided they
		/// derive from ValuePlug too, and they can deal with them
		/// in setFrom().
		bool acceptsInput( const Plug *input ) const override;
		/// Reimplemented so that values can be propagated from inputs.
		void setInput( PlugPtr input ) override;

		PlugPtr createCounterpart( const std::string &name, Direction direction ) const override;

		/// Returns true if it is valid to call setFrom(), setToDefault(),
		/// or setValue() on this plug. False will be returned if the plug
		/// has an input connection or the ReadOnly flag is set.
		bool settable() const;

		/// Must be implemented to set the value of this Plug from the other Plug,
		/// performing any necessary conversions on the input value. Should throw
		/// an exception if other is of an unsupported type.
		virtual void setFrom( const ValuePlug *other );

		/// Sets the value to the default for this plug. The default
		/// implementation is sufficient for all subclasses except those
		/// where the number of child plugs varies based on the value.
		virtual void setToDefault();
		/// Returns true if the current value of the plug is the same
		/// as the default value. The default implementation is sufficient
		/// for all subclasses except those where the number of child plugs
		/// varies based on the value.
		/// > Note : If a plug's value is being driven by a ComputeNode,
		/// > we always consider it to be non-default, because it may vary
		/// > by context. `isSetToDefault()` does not trigger computes.
		virtual bool isSetToDefault() const;

		/// Returns a hash to represent the value of this plug
		/// in the current context.
		virtual IECore::MurmurHash hash() const;
		/// Convenience function to append the hash to h.
		void hash( IECore::MurmurHash &h ) const;

		/// Specifies the methodology used to cache the value
		/// and hash for output plugs.
		enum class CachePolicy
		{
			/// No caching is performed. Suitable for
			/// extremely quick processes. Also useful
			/// to avoid double-counting of cache memory when
			/// a compute always returns a sub-object of another
			/// cache entry.
			Uncached,
			/// Suitable for regular processes that don't spawn
			/// TBB tasks. It is essential that any task-spawning
			/// processes use one of the dedicated policies below.
			Standard,
			/// Suitable for processes that spawn TBB tasks.
			/// Threads waiting for the same result will collaborate
			/// to perform tasks together until the work is complete.
			TaskCollaboration,
			/// Suitable for processes that spawn TBB tasks. Threads
			/// waiting for an in-progress compute will block until
			/// it is complete. In theory this is inferior to TaskCollaboration,
			/// but due to TBB overhead it may be preferable for small
			/// but frequent computes.
			TaskIsolation,
			/// Legacy policy, to be removed.
			Legacy<commit_msg>ValuePlug : Add a todo regarding cache policies<commit_after>//////////////////////////////////////////////////////////////////////////
//
//  Copyright (c) 2011-2012, <NAME>. All rights reserved.
//  Copyright (c) 2013, Image Engine Design Inc. All rights reserved.
//
//  Redistribution and use in source and binary forms, with or without
//  modification, are permitted provided that the following conditions are
//  met:
//
//      * Redistributions of source code must retain the above
//        copyright notice, this list of conditions and the following
//        disclaimer.
//
//      * Redistributions in binary form must reproduce the above
//        copyright notice, this list of conditions and the following
//        disclaimer in the documentation and/or other materials provided with
//        the distribution.
//
//      * Neither the name of <NAME> nor the names of
//        any other contributors to this software may be used to endorse or
//        promote products derived from this software without specific prior
//        written permission.
//
//  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
//  IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
//  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
//  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
//  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
//  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
//  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
//  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
//  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
//  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
//  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////

#ifndef GAFFER_VALUEPLUG_H
#define GAFFER_VALUEPLUG_H

#include "Gaffer/Plug.h"

#include "IECore/Object.h"

namespace Gaffer
{

IE_CORE_FORWARDDECLARE( DependencyNode )

/// The Plug base class defines the concept of a connection
/// point with direction. The ValuePlug class extends this concept
/// to allow the connections to pass values between connection
/// points, and for DependencyNode::compute() to be used to compute output
/// values.
class GAFFER_API ValuePlug : public Plug
{

	public :

		/// Constructs a ValuePlug which can be used as a parent for other ValuePlugs.
		ValuePlug( const std::string &name=defaultName<ValuePlug>(), Direction direction=In, unsigned flags=Default );
		~ValuePlug() override;

		GAFFER_PLUG_DECLARE_TYPE( Gaffer::ValuePlug, ValuePlugTypeId, Plug );

		bool acceptsChild( const GraphComponent *potentialChild ) const override;
		/// Accepts the input only if it is derived from ValuePlug.
		/// Derived classes may accept more types provided they
		/// derive from ValuePlug too, and they can deal with them
		/// in setFrom().
		bool acceptsInput( const Plug *input ) const override;
		/// Reimplemented so that values can be propagated from inputs.
		void setInput( PlugPtr input ) override;

		PlugPtr createCounterpart( const std::string &name, Direction direction ) const override;

		/// Returns true if it is valid to call setFrom(), setToDefault(),
		/// or setValue() on this plug. False will be returned if the plug
		/// has an input connection or the ReadOnly flag is set.
		bool settable() const;

		/// Must be implemented to set the value of this Plug from the other Plug,
		/// performing any necessary conversions on the input value. Should throw
		/// an exception if other is of an unsupported type.
		virtual void setFrom( const ValuePlug *other );

		/// Sets the value to the default for this plug. The default
		/// implementation is sufficient for all subclasses except those
		/// where the number of child plugs varies based on the value.
		virtual void setToDefault();
		/// Returns true if the current value of the plug is the same
		/// as the default value. The default implementation is sufficient
		/// for all subclasses except those where the number of child plugs
		/// varies based on the value.
		/// > Note : If a plug's value is being driven by a ComputeNode,
		/// > we always consider it to be non-default, because it may vary
		/// > by context. `isSetToDefault()` does not trigger computes.
		virtual bool isSetToDefault() const;

		/// Returns a hash to represent the value of this plug
		/// in the current context.
		virtual IECore::MurmurHash hash() const;
		/// Convenience function to append the hash to h.
		void hash( IECore::MurmurHash &h ) const;

		/// Specifies the methodology used to cache the value
		/// and hash for output plugs.
		enum class CachePolicy
		{
			/// No caching is performed. Suitable for
			/// extremely quick processes. Also useful
			/// to avoid double-counting of cache memory when
			/// a compute always returns a sub-object of another
			/// cache entry.
			Uncached,
			/// Suitable for regular processes that don't spawn
			/// TBB tasks. It is essential that any task-spawning
			/// processes use one of the dedicated policies below.
			/// \todo It isn't actually clear that the locking of the
			/// Standard policy is an improvement over the non-locked
			/// Legacy policy. Locking on a downstream Standard
			/// compute might prevent multiple threads from participating
			/// in an upstream TaskCollaboration. And for small computes
			/// that are unlikely to be needed by multiple threads,
			/// we may well prefer to avoid the contention. Note that
			/// many scene computes may fit this category, as every
			/// non-filtered location is implemented as a very cheap
			/// pass-through compute. There's also a decent argument
			/// that any non-trivial amount of work should be using TBB,
			/// so it would be a mistake to do anything expensive with
			/// a Standard policy anyway.
			Standard,
			/// Suitable for processes that spawn TBB tasks.
			/// Threads waiting for the same result will collaborate
			/// to perform tasks together until the work is complete.
			TaskCollaboration,
			/// Suitable for processes that spawn TBB tasks. Threads
			/// waiting for an in-progress compute will block until
			/// it is complete. In theory this is inferior to TaskCollaboration,
			/// but due to TBB overhead it may be preferable for small
			/// but frequent computes.
			TaskIsolation,
			/// Legacy policy, to be removed.
			Legacy
{'fraction_non_alphanumeric': 0.09833795013850416, 'fraction_numerical': 0.001955352778230406, 'mean_word_length': 2.806201550387597, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 15, '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': '633294', 'n_tokens_mistral': 3379, 'n_tokens_neox': 2970, 'n_words': 1579}