<commit_before>/*
 *  ComponentFactoryException.h
 *  MWorksCore
 *
 *  Created by bkennedy on 12/3/07.
 *  Copyright 2007 MIT. All rights reserved.
 *
 */

#include "MWorksMacros.h"

#ifndef COMPONENT_FACTORY_EXCEPTION_H_
#define COMPONENT_FACTORY_EXCEPTION_H_
BEGIN_NAMESPACE_MW
class ComponentFactoryException : public std::exception {
protected:
	std::string _what;
	std::string _referenceID;
public:
	ComponentFactoryException(const std::string &refID) {
        if(refID.empty()){
            _referenceID = refID;
        } else {
            _referenceID = "<unknown>";
        }
	}
	
	virtual ~ComponentFactoryException() throw() {}
	virtual const char* what() const throw() = 0;	
	
	virtual const char* referenceID() const throw() {
		return _referenceID.c_str();
	}
};

class MissingAttributeException : public ComponentFactoryException {
public:
	MissingAttributeException(const std::string &referenceID,
							   const std::string &errorMessage) : ComponentFactoryException(referenceID) {
		_what = errorMessage;
	}
	
	virtual ~MissingAttributeException() throw() {}
	
	virtual const char* what() const throw() {
		return _what.c_str();
	}
};

class UnknownAttributeException : public ComponentFactoryException {
public:
    UnknownAttributeException(const std::string &referenceID, const std::string &attributeName) :
        ComponentFactoryException(referenceID)
    {
        _what = "Unknown attribute: \"" + attributeName + "\"";
    }
    
    virtual ~UnknownAttributeException() throw() {}
    
    virtual const char* what() const throw() {
        return _what.c_str();
    }
};

class InvalidReferenceException : public ComponentFactoryException {
public:
	InvalidReferenceException(const std::string &referenceID,
							   const std::string &name,
							   const std::string &value) : ComponentFactoryException(referenceID) {
		// WTF? This is totally not how this is used
		//_what = "invalid reference for \"" + value + "\" of type \"" + name + "\"";
		_what = "invalid value \"" + value + "\" for attribute \"" + name + "\"";
	}
	
	virtual ~InvalidReferenceException() throw() {}
	
	virtual const char* what() const throw() {
		return _what.c_str();
	}
};

class InvalidAttributeException : public ComponentFactoryException {
public:
	InvalidAttributeException(const std::string &referenceID,
							   const std::string &name,
							   const std::string &value) : ComponentFactoryException(referenceID) {
		_what = "invalid value (" + value + ") for attribute \"" + name + "\"";
	}
	
	virtual ~InvalidAttributeException() throw() {}
	
	virtual const char* what() const throw() {
		return _what.c_str();
	}
};

class MissingReferenceException : public ComponentFactoryException {
protected:
public:
	MissingReferenceException(const std::string &referenceID,
							   const std::string &name,
							   const std::string &value) : ComponentFactoryException(referenceID) {
		_what = "can't find a reference for \"" + value + "\" for attribute \"" + name + "\"";
	}
	
	virtual ~MissingReferenceException() throw() {}
	
	virtual const char* what() const throw() {
		return _what.c_str();
	}
};
END_NAMESPACE_MW

#endif<commit_msg>ComponentFactoryException now inherits from SimpleException<commit_after>/*
 *  ComponentFactoryException.h
 *  MWorksCore
 *
 *  Created by bkennedy on 12/3/07.
 *  Copyright 2007 MIT. All rights reserved.
 *
 */

#ifndef COMPONENT_FACTORY_EXCEPTION_H_
#define COMPONENT_FACTORY_EXCEPTION_H_

#include "MWorksMacros.h"
#include "Exceptions.h"


BEGIN_NAMESPACE_MW


class ComponentFactoryException : public SimpleException {

public:
	virtual ~ComponentFactoryException() throw() { }

	ComponentFactoryException(const std::string &refID, const std::string &message) :
        SimpleException(M_PARSER_MESSAGE_DOMAIN, message)
    {
        if (refID.empty()) {
            _referenceID = refID;
        } else {
            _referenceID = "<unknown>";
        }
	}
	
	const std::string& referenceID() const {
		return _referenceID;
	}

private:
	std::string _referenceID;
    
};


class MissingAttributeException : public ComponentFactoryException {
public:
	MissingAttributeException(const std::string &referenceID, const std::string &errorMessage) :
        ComponentFactoryException(referenceID, errorMessage)
    { }
};


class UnknownAttributeException : public ComponentFactoryException {
public:
    UnknownAttributeException(const std::string &referenceID, const std::string &attributeName) :
        ComponentFactoryException(referenceID, "Unknown attribute: \"" + attributeName + "\"")
    { }
};


class InvalidReferenceException : public ComponentFactoryException {
public:
	InvalidReferenceException(const std::string &referenceID, const std::string &name, const std::string &value) :
        ComponentFactoryException(referenceID, "invalid value \"" + value + "\" for attribute \"" + name + "\"")
    { }
};


class InvalidAttributeException : public ComponentFactoryException {
public:
	InvalidAttributeException(const std::string &referenceID, const std::string &name, const std::string &value) :
        ComponentFactoryException(referenceID, "invalid value (" + value + ") for attribute \"" + name + "\"")
    { }
};


class MissingReferenceException : public ComponentFactoryException {
public:
	MissingReferenceException(const std::string &referenceID, const std::string &name, const std::string &value) :
        ComponentFactoryException(referenceID,
                                  "can't find a reference for \"" + value + "\" for attribute \"" + name + "\"")
    { }
};


END_NAMESPACE_MW


#endif






















{'fraction_non_alphanumeric': 0.11554921540656206, 'fraction_numerical': 0.0033880171184022824, 'mean_word_length': 3.9462081128747797, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4815546', 'n_tokens_mistral': 1668, 'n_tokens_neox': 1539, 'n_words': 386}