<commit_before>// PropertyTable.cpp
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
/*
* Copyright (c)  2011-12, Stanford University. All rights reserved. 
* Use of the OpenSim software in source form is permitted provided that the following
* conditions are met:
* 	1. The software is used only for non-commercial research and education. It may not
*     be used in relation to any commercial activity.
* 	2. The software is not distributed or redistributed.  Software distribution is allowed 
*     only through https://simtk.org/home/opensim.
* 	3. Use of the OpenSim software or derivatives must be acknowledged in all publications,
*      presentations, or documents describing work in which OpenSim or derivatives are used.
* 	4. Credits to developers may not be removed from executables
*     created from modifications of the source.
* 	5. Modifications of source code must retain the above copyright notice, this list of
*     conditions and the following disclaimer. 
* 
*  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; 
*  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
*  OR BUSINESS INTERRUPTION) 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.
*/

//============================================================================
// INCLUDES
//============================================================================
#include "PropertyTable.h"


using namespace OpenSim;
using namespace SimTK;
using namespace std;

//_____________________________________________________________________________
// Default constructor is inline

//_____________________________________________________________________________
// Copy constructor has to clone the source properties.
PropertyTable::PropertyTable(const PropertyTable& source)
{
	replaceProperties(source.properties);
}

//_____________________________________________________________________________
// Destructor must deep-delete the properties since they are owned by the
// PropertyTable.
PropertyTable::~PropertyTable()
{
	deleteProperties();
}

//_____________________________________________________________________________
// Copy assignment has to clone the source properties.
PropertyTable& PropertyTable::operator=(const PropertyTable& source)
{
    if (&source != this)
	    replaceProperties(source.properties);
	return *this;
}

//_____________________________________________________________________________
// Reinitialize the table to be completely empty.
void PropertyTable::clear() {
    deleteProperties();
}

//_____________________________________________________________________________
// Equality operator compares each property with the one at the same position.
bool PropertyTable::equals(const PropertyTable& other) const {
    if (getNumProperties() != other.getNumProperties())
        return false;
    for (int i=0; i < getNumProperties(); ++i) {
        if (!(getAbstractPropertyByIndex(i) == other.getAbstractPropertyByIndex(i)))
            return false;
    }
    return true;
}

int PropertyTable::adoptProperty(AbstractProperty* prop)
{
    assert(prop);
    const int          nxtIndex = properties.size();
    const std::string& name     = prop->getName();

    // Unnamed property should have had its Object class name used as its name.
    assert(!name.empty());

    if (hasProperty(name))
        throw OpenSim::Exception
            ("PropertyTable::adoptProperty(): Property " 
            + name + " already in table.");

    propertyIndex[name] = nxtIndex;
    properties.push_back(prop);
    return nxtIndex;
}

const AbstractProperty& PropertyTable::
getAbstractPropertyByIndex(int index) const {
    if (!(0 <= index && index < getNumProperties()))
        throw OpenSim::Exception
            ("PropertyTable::getAbstractPropertyByIndex(): index " 
            + String(index) + " out of range (" 
            + String(getNumProperties()) + " properties in table).");        
    return *properties[index]; 
}

AbstractProperty& PropertyTable::
updAbstractPropertyByIndex(int index) {
    if (!(0 <= index && index < getNumProperties()))
        throw OpenSim::Exception
            ("PropertyTable::updAbstractPropertyByIndex(): index " 
            + String(index) + " out of range (" 
            + String(getNumProperties()) + " properties in table).");        
    return *properties[index]; 
}

const AbstractProperty& PropertyTable::
getAbstractPropertyByName(const std::string& name) const {
    const AbstractProperty* p = getPropertyPtr(name);
    if (p == NULL) throw OpenSim::Exception
        ("PropertyTable::getAbstractPropertyByName(): Property " 
        + name + " not found.");
    return *p;
}

AbstractProperty& PropertyTable::
updAbstractPropertyByName(const std::string& name) {
    AbstractProperty* p = updPropertyPtr(name);
    if (p == NULL) throw OpenSim::Exception
        ("PropertyTable::updAbstractPropertyByName(): Property " 
        + name + " not found.");
    return *p;
}

// Look up the property by name in the map to find its index
// in the property array and return that. If the name isn't there, return -1.
// This method is reused in the implementation of any method that<commit_msg>Improve the error message issued when a constructProperty() call is omitted. (<NAME> ran into this problem.)<commit_after>// PropertyTable.cpp
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
/*
* Copyright (c)  2011-12, Stanford University. All rights reserved. 
* Use of the OpenSim software in source form is permitted provided that the following
* conditions are met:
* 	1. The software is used only for non-commercial research and education. It may not
*     be used in relation to any commercial activity.
* 	2. The software is not distributed or redistributed.  Software distribution is allowed 
*     only through https://simtk.org/home/opensim.
* 	3. Use of the OpenSim software or derivatives must be acknowledged in all publications,
*      presentations, or documents describing work in which OpenSim or derivatives are used.
* 	4. Credits to developers may not be removed from executables
*     created from modifications of the source.
* 	5. Modifications of source code must retain the above copyright notice, this list of
*     conditions and the following disclaimer. 
* 
*  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; 
*  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
*  OR BUSINESS INTERRUPTION) 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.
*/

//============================================================================
// INCLUDES
//============================================================================
#include "PropertyTable.h"


using namespace OpenSim;
using namespace SimTK;
using namespace std;

//_____________________________________________________________________________
// Default constructor is inline

//_____________________________________________________________________________
// Copy constructor has to clone the source properties.
PropertyTable::PropertyTable(const PropertyTable& source)
{
	replaceProperties(source.properties);
}

//_____________________________________________________________________________
// Destructor must deep-delete the properties since they are owned by the
// PropertyTable.
PropertyTable::~PropertyTable()
{
	deleteProperties();
}

//_____________________________________________________________________________
// Copy assignment has to clone the source properties.
PropertyTable& PropertyTable::operator=(const PropertyTable& source)
{
    if (&source != this)
	    replaceProperties(source.properties);
	return *this;
}

//_____________________________________________________________________________
// Reinitialize the table to be completely empty.
void PropertyTable::clear() {
    deleteProperties();
}

//_____________________________________________________________________________
// Equality operator compares each property with the one at the same position.
bool PropertyTable::equals(const PropertyTable& other) const {
    if (getNumProperties() != other.getNumProperties())
        return false;
    for (int i=0; i < getNumProperties(); ++i) {
        if (!(getAbstractPropertyByIndex(i) == other.getAbstractPropertyByIndex(i)))
            return false;
    }
    return true;
}

int PropertyTable::adoptProperty(AbstractProperty* prop)
{
    assert(prop);
    const int          nxtIndex = properties.size();
    const std::string& name     = prop->getName();

    // Unnamed property should have had its Object class name used as its name.
    assert(!name.empty());

    if (hasProperty(name))
        throw OpenSim::Exception
            ("PropertyTable::adoptProperty(): Property " 
            + name + " already in table.");

    propertyIndex[name] = nxtIndex;
    properties.push_back(prop);
    return nxtIndex;
}

const AbstractProperty& PropertyTable::
getAbstractPropertyByIndex(int index) const {
    if (index == SimTK::InvalidIndex)
        throw OpenSim::Exception
           ("PropertyTable::getAbstractPropertyByIndex(): uninitialized " 
            "property index -- did you forget a constructProperty() call?");
    if (!(0 <= index && index < getNumProperties()))
        throw OpenSim::Exception
           ("PropertyTable::getAbstractPropertyByIndex(): index " 
            + String(index) + " out of range (" 
            + String(getNumProperties()) + " properties in table).");        
    return *properties[index]; 
}

AbstractProperty& PropertyTable::
updAbstractPropertyByIndex(int index) {
    if (index == SimTK::InvalidIndex)
        throw OpenSim::Exception
           ("PropertyTable::updAbstractPropertyByIndex(): uninitialized " 
            "property index -- did you forget a constructProperty() call?");
    if (!(0 <= index && index < getNumProperties()))
        throw OpenSim::Exception
           ("PropertyTable::updAbstractPropertyByIndex(): index " 
            + String(index) + " out of range (" 
            + String(getNumProperties()) + " properties in table).");        
    return *properties[index]; 
}

const AbstractProperty& PropertyTable::
getAbstractPropertyByName(const std::string& name) const {
    const AbstractProperty* p = getPropertyPtr(name);
    if (p == NULL) throw OpenSim::Exception
        ("PropertyTable::getAbstractPropertyByName(): Property " 
        + name + " not found.");
    return *p;
}

AbstractProperty& PropertyTable::
updAbstractPropertyByName(const std::string& name) {
    AbstractProperty* p = updPropertyPtr(name);
    if (p == NULL) throw OpenSim::Exception
        ("PropertyTable::updAbstractPropertyByName(): Property " 
        + name + " not found.");
    return *p;
}

// Look up the property by name in the map to find its index
// in the property array and return that. If the name isn't there, return -1.
// This method is reused in the implementation of any method that
{'fraction_non_alphanumeric': 0.12250971315202117, 'fraction_numerical': 0.0024799537075307927, 'mean_word_length': 4.161262798634812, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 6, 'https://': 2, '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': '796235', 'n_tokens_mistral': 2929, 'n_tokens_neox': 2769, 'n_words': 1076}