<commit_before>/*
 * FlexEnumParam.cpp
 *
 * Copyright (C) 2017 by Universitaet Stuttgart (VIS). 
 * Alle Rechte vorbehalten.
 */

#include "stdafx.h"
#include "mmcore/param/FlexEnumParam.h"
#include "vislib/IllegalStateException.h"
#include "vislib/StringConverter.h"
#include "vislib/UTF8Encoder.h"
#include <set>

using namespace megamol::core::param;


/*
 * FlexEnumParam::FlexEnumParam
 */
FlexEnumParam::FlexEnumParam(const std::string& initVal)
        : AbstractParam(), val(initVal), values() {
    // intentionally empty
}


/*
 * FlexEnumParam::~FlexEnumParam
 */
FlexEnumParam::~FlexEnumParam(void) {
    // intentionally empty
}


/*
 * FlexEnumParam::ClearTypePairs
 */
void megamol::core::param::FlexEnumParam::ClearValues(void) {
    this->SetHash(this->GetHash() + 1);
    this->values.clear();
}


/*
 * FlexEnumParam::Definition
 */
void FlexEnumParam::Definition(vislib::RawStorage& outDef) const {
    vislib::StringA utf8;
    unsigned int s = 6;
    unsigned int c = 0;
    for (auto &v : this->values) {
        s += v.length() + 1; //terminating zero
    }
    s += sizeof(unsigned int);

    outDef.AssertSize(s);
    memcpy(outDef.AsAt<char>(0), "MMFENU", 6);
    s = 6 + sizeof(unsigned int);
    std::set<std::string> sorted(this->values.begin(), this->values.end());
    for (auto &v: sorted) {
        unsigned int strsize = v.length() + 1;
        memcpy(outDef.AsAt<char>(s), v.c_str(), strsize);
        s += strsize;
        c++;
    }
    *outDef.AsAt<unsigned int>(6) = c;
}


/*
 * FlexEnumParam::ParseValue
 */
bool FlexEnumParam::ParseValue(const vislib::TString& v) {
    try {
        this->SetValue(std::string(T2A(v)));
        //auto iter = this->values.find(std::string(T2A(v)));
        //if (iter == this->values.end()) {
        //    return false;
        //} else {
        //    this->SetValue(*iter);<commit_msg>successful parsing should return true<commit_after>/*
 * FlexEnumParam.cpp
 *
 * Copyright (C) 2017 by Universitaet Stuttgart (VIS). 
 * Alle Rechte vorbehalten.
 */

#include "stdafx.h"
#include "mmcore/param/FlexEnumParam.h"
#include "vislib/IllegalStateException.h"
#include "vislib/StringConverter.h"
#include "vislib/UTF8Encoder.h"
#include <set>

using namespace megamol::core::param;


/*
 * FlexEnumParam::FlexEnumParam
 */
FlexEnumParam::FlexEnumParam(const std::string& initVal)
        : AbstractParam(), val(initVal), values() {
    // intentionally empty
}


/*
 * FlexEnumParam::~FlexEnumParam
 */
FlexEnumParam::~FlexEnumParam(void) {
    // intentionally empty
}


/*
 * FlexEnumParam::ClearTypePairs
 */
void megamol::core::param::FlexEnumParam::ClearValues(void) {
    this->SetHash(this->GetHash() + 1);
    this->values.clear();
}


/*
 * FlexEnumParam::Definition
 */
void FlexEnumParam::Definition(vislib::RawStorage& outDef) const {
    vislib::StringA utf8;
    unsigned int s = 6;
    unsigned int c = 0;
    for (auto &v : this->values) {
        s += v.length() + 1; //terminating zero
    }
    s += sizeof(unsigned int);

    outDef.AssertSize(s);
    memcpy(outDef.AsAt<char>(0), "MMFENU", 6);
    s = 6 + sizeof(unsigned int);
    std::set<std::string> sorted(this->values.begin(), this->values.end());
    for (auto &v: sorted) {
        unsigned int strsize = v.length() + 1;
        memcpy(outDef.AsAt<char>(s), v.c_str(), strsize);
        s += strsize;
        c++;
    }
    *outDef.AsAt<unsigned int>(6) = c;
}


/*
 * FlexEnumParam::ParseValue
 */
bool FlexEnumParam::ParseValue(const vislib::TString& v) {
    try {
        this->SetValue(std::string(T2A(v)));
        return true;
        //auto iter = this->values.find(std::string(T2A(v)));
        //if (iter == this->values.end()) {
        //    return false;
        //} else {
        //    this->SetValue(*iter);
{'fraction_non_alphanumeric': 0.17182949430765157, 'fraction_numerical': 0.009001853322742918, 'mean_word_length': 3.2118171683389076, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 33, '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': '2823263', 'n_tokens_mistral': 1349, 'n_tokens_neox': 1282, 'n_words': 243}