<commit_before>#ifndef _PropertyDblVec_h_
#define _PropertyDblVec_h_
// PropertyDblVec.h
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
/*
* Copyright (c) 2010, Stanford University. 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 the Stanford University nor the names of its 
*    contributors 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. 
*/

#ifdef WIN32
#pragma warning( disable : 4251 )
#endif

#include "osimCommonDLL.h"
#include <string>
#include "Property_Deprecated.h"
#include "SimTKcommon.h"

//=============================================================================
//=============================================================================
/**
 * Class PropertyDblVec_ extends class Property.  It consists of a small
 * vector of doubles (i.e., SimTK::Vec<M>) and the methods for accessing
 * and modifying this Vec<M>.
 *
 * @version 1.0
 * @author <NAME>, <NAME>
 */
namespace OpenSim { 

template<int M> class PropertyDblVec_ : public Property_Deprecated
{

//=============================================================================
// DATA
//=============================================================================
private:
	/** Vector of doubles. */
	SimTK::Vec<M> _vec;

	/** Array representation for serialization */
	mutable Array<double> _array;

	char _typeAsString[7];

//=============================================================================
// METHODS
//=============================================================================
	//--------------------------------------------------------------------------
	// CONSTRUCTION
	//--------------------------------------------------------------------------
public:
	/** Default constructor */
	PropertyDblVec_() : Property_Deprecated(DblVec, "DblVec_PropertyName")
		{ sprintf(_typeAsString, "DblVec%i", M);
		  setAllowableListSize(M);	  
		};
	/** Construct from name and value */
	PropertyDblVec_(const std::string &aName, const SimTK::Vec<M>& aVec)
    :   Property_Deprecated(DblVec, aName) 
		{ sprintf(_typeAsString, "DblVec%i", M);  setValue(aVec);
		  setAllowableListSize(M);

		};
	/** Construct from name and value as an Array<double> */
	PropertyDblVec_(const std::string &aName, const Array<double> &anArray)
    :   Property_Deprecated(DblVec, aName)
		{ sprintf(_typeAsString, "DblVec%i", M);  setValue(anArray);
		  setAllowableListSize(M);
		};
	/** Copy constructor */
	PropertyDblVec_(const PropertyDblVec_ &aProperty)
    :   Property_Deprecated(aProperty)
		{ setValue(aProperty._vec);};

	/* Return a copy of this property */
	/*virtual*/ PropertyDblVec_* clone() const {
		PropertyDblVec_* prop = new PropertyDblVec_<M>(*this);
		return prop;
	};

	//--------------------------------------------------------------------------
	// OPERATORS
	//--------------------------------------------------------------------------
public:
	/** Assign this property to another */
	PropertyDblVec_& operator=(const PropertyDblVec_ &aProperty){
		Property_Deprecated::operator=(aProperty);
		_vec = aProperty._vec;
		return(*this);
	};

	//--------------------------------------------------------------------------
	// GET AND SET
	//--------------------------------------------------------------------------
public:
	/** Get the type of this property as a string. */
	virtual std::string getTypeName() const OVERRIDE_11 {
		return "double";
	};

	// VALUE
	/** set value of property from an equivalently sized Vec */
	virtual void setValue(const SimTK::Vec<M> &aVec) { 
		assert(aVec.size()==M); _vec=aVec; 
	};
	/** set value of this property from an array of doubles of equal or greater length */
	virtual void setValue(const Array<double> &anArray){
		assert(anArray.getSize() >= M);
		for(int i=0;i<M; i++)
			_vec[i] = anArray[i];
		_array = anArray;
	};
	/** get writable reference to the value */
	virtual SimTK::Vec<M>& getValueDblVec() {return _vec; };
	/** get const (read-only) reference to the value */
	virtual const SimTK::Vec<M>& getValueDblVec() const {return _vec; };
	/** set value from double array */
	virtual void setValue(int aSize, const double aArray[]){ // to be used by the serialization code
		assert(aSize == M);
		setValue(SimTK::Vec<M>::getAs(aArray));
	};
#ifndef SWIG
	/** get value as double array */
	virtual const Array<double>& getValueDblArray() const {
		_array.setSize(M);
		for(int i=0;i<M; i++)
			_array[i] = _vec[i];
		return _array;
	};
#endif
	/** Nonconst version of accessor for use by GUI.
	 * Beware: changes to returned array will not change _vec member as it should
	 * both _vec and _array should point to same memory to fix this issue
	 */
	virtual Array<double>& getValueDblArray() {
		_array.setSize(M);
		for(int i=0;i<M; i++)
			_array[i] = _vec[i];
		return _array;
	};
	/** Get a constant String represeting the value of this property. */
	virtual std::string toString() const {
		std::string str = "(";
		char dbl[256];
			for(int i=0; i < _vec.size(); i++){
				sprintf(dbl, "%g", _vec[i]);
				str += (i>0?" ":"") + std::string(dbl);
			}
		str += ")";
		return str;
	};
	// SIZE
	virtual int getArraySize() const { return M; }

    virtual bool isArrayProperty() const {return true;}

    virtual int getNumValues() const OVERRIDE_11 {return M;}
//=============================================================================
};	// END of class PropertyDblVec_

}; //OpenSim namespace
//=============================================================================
//=============================================================================

#endif //__PropertyDblVec__h__<commit_msg>Fixed old school PropertyDblVec_<M> so that writing through the value reference actually does change the value!<commit_after>#ifndef _PropertyDblVec_h_
#define _PropertyDblVec_h_
// PropertyDblVec.h
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
/*
* Copyright (c) 2010, Stanford University. 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 the Stanford University nor the names of its 
*    contributors 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. 
*/

#ifdef WIN32
#pragma warning( disable : 4251 )
#endif

#include "osimCommonDLL.h"
#include <string>
#include "Property_Deprecated.h"
#include "SimTKcommon.h"

//=============================================================================
//=============================================================================
/**
 * Class PropertyDblVec_ extends class Property.  It consists of a small
 * vector of doubles (i.e., SimTK::Vec<M>) and the methods for accessing
 * and modifying this Vec<M>.
 *
 * @author <NAME>, <NAME>, <NAME>
 */
namespace OpenSim { 

template<int M> class PropertyDblVec_ : public Property_Deprecated
{

//=============================================================================
// DATA
//=============================================================================
private:
	// Store in an Array for serialization; we'll fake up the Vec<M> when
    // we need it using the Array's storage.
	Array<double> _dblvec;

//=============================================================================
// METHODS
//=============================================================================
	//--------------------------------------------------------------------------
	// CONSTRUCTION
	//--------------------------------------------------------------------------
public:
	/** Default constructor */
	PropertyDblVec_() : Property_Deprecated(DblVec, "DblVec_PropertyName")
		{ setAllowableListSize(M);
          _dblvec.setSize(M);
		}
	/** Construct from name and value */
	PropertyDblVec_(const std::string &aName, const SimTK::Vec<M>& aVec)
    :   Property_Deprecated(DblVec, aName) 
		{ setAllowableListSize(M);
          _dblvec.setSize(M);
          setValue(aVec);
		}
	/** Construct from name and value as an Array<double> */
	PropertyDblVec_(const std::string &aName, const Array<double> &anArray)
    :   Property_Deprecated(DblVec, aName)
		{ setAllowableListSize(M);
          _dblvec.setSize(M);    
          setValue(anArray);
		}
	
    // default destructor, copy constructor, copy assignment

	/* Return a copy of this property */
	PropertyDblVec_* clone() const OVERRIDE_11 {
		PropertyDblVec_* prop = new PropertyDblVec_<M>(*this);
		return prop;
	}

public:

	//--------------------------------------------------------------------------
	// GET AND SET
	//--------------------------------------------------------------------------
public:
	/** Get the type of this property as a string. */
	std::string getTypeName() const OVERRIDE_11 {
		return "double";
	}

	// VALUE
	/** set value of property from an equivalently sized Vec */
	void setValue(const SimTK::Vec<M> &aVec) { 
		SimTK::Vec<M>::updAs(&_dblvec[0])=aVec; 
	}
	/** set value of this property from an array of doubles of equal or greater length */
	void setValue(const Array<double> &anArray) OVERRIDE_11 {
		assert(anArray.getSize() >= M);
		for(int i=0;i<M; i++)
			_dblvec[i] = anArray[i];
	}
	/** get writable reference to the value */
	SimTK::Vec<M>& getValueDblVec() {return SimTK::Vec3::updAs(&_dblvec[0]); }
	/** get const (read-only) reference to the value */
	const SimTK::Vec<M>& getValueDblVec() const {return SimTK::Vec3::getAs(&_dblvec[0]); };
	/** set value from double array */ // to be used by the serialization code
	void setValue(int aSize, const double aArray[]) OVERRIDE_11 { 
		assert(aSize == M);
		setValue(SimTK::Vec<M>::getAs(aArray));
	};
#ifndef SWIG
	/** get value as double array */
    const Array<double>& getValueDblArray() const OVERRIDE_11 {return _dblvec;}
#endif
	/** Nonconst version of accessor for use by GUI. */
    Array<double>& getValueDblArray() OVERRIDE_11 {return _dblvec;}

	/** Get a constant String represeting the value of this property. */
	std::string toString()  const OVERRIDE_11 {
		std::string str = "(";
		char dbl[256];
			for(int i=0; i < M; i++){
				sprintf(dbl, "%g", _dblvec[i]);
				str += (i>0?" ":"") + std::string(dbl);
			}
		str += ")";
		return str;
	};
	// SIZE
	int getArraySize() const OVERRIDE_11 { return M; }

    bool isArrayProperty() const OVERRIDE_11 {return true;}

    int getNumValues() const OVERRIDE_11 {return M;}
//=============================================================================
};	// END of class PropertyDblVec_

}; //OpenSim namespace
//=============================================================================
//=============================================================================

#endif //__PropertyDblVec__h__
{'fraction_non_alphanumeric': 0.26788810977908467, 'fraction_numerical': 0.0049762497172585385, 'mean_word_length': 3.465993265993266, 'pattern_counts': {'":': 2, '<': 50, '<?xml version=': 0, '>': 48, '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': '4488481', 'n_tokens_mistral': 3878, 'n_tokens_neox': 3490, 'n_words': 1197}