<commit_before>/*Copyright 2010 <NAME>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.*/

#ifndef DATATABLECOLLECTIONBASE_H
#define DATATABLECOLLECTIONBASE_H

#include "datatable.h"
#include "collection.h"

GUTIL_BEGIN_NAMESPACE( DataObjects );


template <class DataTable> class DataTableCollectionBase :
        public Collection<DataTable>,
        public Core::Interfaces::IClonable< DataTableCollectionBase<DataTable> >
{
    friend class DataSet;
    friend class TableData;
    friend class SharedSetData;

public:

    DataSet Set() const;


protected:

    DataTableCollectionBase(SharedSetData *d){
        _set_data = d;
    }

    virtual ~DataTableCollectionBase(){}

    DataTableCollectionBase(const DataTableCollectionBase<DataTable> &o){
        o.CloneTo(*this);
    }

    // Protect our clonable interface
    virtual DataTableCollectionBase<DataTable> &CloneTo(DataTableCollectionBase<DataTable> &o) const{
        o.Clear();

        for(int i = 0; i < Collection<DataTable>::Size(); i++)
            o.Add(Collection<DataTable>::At(i).Clone());

        return o;
    }

    virtual void on_add(DataTable *t) const
    {
        // Remove ourselves from our parent set
        SharedSetData *sd;
        if((sd = t->table_data().SetData()))
            ((DataTableCollectionBase<DataTable> &)sd->Tables()).RemoveOne(*t);

        // Set our new set data to this one
        t->table_data().SetSetData(_set_data);
    }

    virtual void validate_new_item(const DataTable &t) const
            throw(Core::ValidationException)
    {
        if(Contains(t))
            THROW_NEW_GUTIL_EXCEPTION(Core::ValidationException,
                                      "Table already exists in data set");
    }<commit_msg>Fixed the bug that was causing the test cases to fail.<commit_after>/*Copyright 2010 <NAME>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.*/

#ifndef DATATABLECOLLECTIONBASE_H
#define DATATABLECOLLECTIONBASE_H

#include "datatable.h"
#include "collection.h"

GUTIL_BEGIN_NAMESPACE( DataObjects );


template <class DataTable> class DataTableCollectionBase :
        public Collection<DataTable>,
        public Core::Interfaces::IClonable< DataTableCollectionBase<DataTable> >
{
    friend class DataSet;
    friend class TableData;
    friend class SharedSetData;

public:

    DataSet Set() const;


protected:

    DataTableCollectionBase(SharedSetData *d){
        _set_data = d;
    }

    virtual ~DataTableCollectionBase(){}

    DataTableCollectionBase(const DataTableCollectionBase<DataTable> &o){
        o.CloneTo(*this);
    }

    // Protect our clonable interface
    virtual DataTableCollectionBase<DataTable> &CloneTo(DataTableCollectionBase<DataTable> &o) const{
        o.Clear();

        for(int i = 0; i < Collection<DataTable>::Size(); i++)
            o.Add(Collection<DataTable>::At(i).Clone());

        return o;
    }

    virtual void on_add(DataTable *t) const
    {
        // Remove ourselves from our parent set (if it's different from the one we're now setting)
        SharedSetData *sd;
        if((sd = t->table_data().SetData()) &&
           _set_data != sd)
        {
            ((DataTableCollectionBase<DataTable> &)sd->Tables()).RemoveOne(*t);

            // Set our new set data to this one
            t->table_data().SetSetData(_set_data);
        }
    }

    virtual void validate_new_item(const DataTable &t) const
            throw(Core::ValidationException)
    {
        if(Contains(t))
            THROW_NEW_GUTIL_EXCEPTION(Core::ValidationException,
                                      "Table already exists in data set");
    }
{'fraction_non_alphanumeric': 0.09200174825174826, 'fraction_numerical': 0.003933566433566434, 'mean_word_length': 3.1458333333333335, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4316020', 'n_tokens_mistral': 1308, 'n_tokens_neox': 1246, 'n_words': 391}