| [89a67f] | 1 | /* | 
|---|
|  | 2 | * Project: MoleCuilder | 
|---|
|  | 3 | * Description: creates and alters molecular systems | 
|---|
| [0aa122] | 4 | * Copyright (C)  2010-2012 University of Bonn. All rights reserved. | 
|---|
| [89a67f] | 5 | * Please see the LICENSE file or "Copyright notice" in builder.cpp for details. | 
|---|
|  | 6 | */ | 
|---|
|  | 7 |  | 
|---|
|  | 8 | /* | 
|---|
|  | 9 | * StringParameter.cpp | 
|---|
|  | 10 | * | 
|---|
|  | 11 | *  Created on: Sep 30, 2011 | 
|---|
|  | 12 | *      Author: heber | 
|---|
|  | 13 | */ | 
|---|
|  | 14 |  | 
|---|
|  | 15 | // include config.h | 
|---|
|  | 16 | #ifdef HAVE_CONFIG_H | 
|---|
|  | 17 | #include <config.h> | 
|---|
|  | 18 | #endif | 
|---|
|  | 19 |  | 
|---|
|  | 20 | #include "CodePatterns/MemDebug.hpp" | 
|---|
|  | 21 |  | 
|---|
|  | 22 | #include <string> | 
|---|
|  | 23 |  | 
|---|
|  | 24 | #include "CodePatterns/Assert.hpp" | 
|---|
|  | 25 |  | 
|---|
|  | 26 | #include "StringParameter.hpp" | 
|---|
|  | 27 |  | 
|---|
|  | 28 | /** Constructor for class StringParameter. | 
|---|
|  | 29 | * | 
|---|
|  | 30 | * @param _name name of this parameter | 
|---|
|  | 31 | */ | 
|---|
|  | 32 | StringParameter::StringParameter(const std::string &_name) : | 
|---|
|  | 33 | Parameter(_name), | 
|---|
|  | 34 | ValueSet(false) | 
|---|
|  | 35 | {} | 
|---|
|  | 36 |  | 
|---|
|  | 37 | /** Constructor for class StringParameter. | 
|---|
|  | 38 | * | 
|---|
|  | 39 | * @param _name name of this parameter | 
|---|
|  | 40 | * @param _value value of this parameter | 
|---|
|  | 41 | */ | 
|---|
|  | 42 | StringParameter::StringParameter(const std::string &_name, const std::string &_value) : | 
|---|
|  | 43 | Parameter(_name), | 
|---|
|  | 44 | ValueSet(true), | 
|---|
|  | 45 | value(_value) | 
|---|
|  | 46 | {} | 
|---|
|  | 47 |  | 
|---|
|  | 48 | /** Destructor of class StringParameter. | 
|---|
|  | 49 | * | 
|---|
|  | 50 | */ | 
|---|
|  | 51 | StringParameter::~StringParameter() | 
|---|
|  | 52 | {} | 
|---|
|  | 53 |  | 
|---|
|  | 54 | /** Compare function for class StringParameter. | 
|---|
|  | 55 | * | 
|---|
|  | 56 | * @param _instance instance to compare to | 
|---|
|  | 57 | * @return true - both have the same \a StringParameter::value, false - else | 
|---|
|  | 58 | */ | 
|---|
|  | 59 | bool StringParameter::operator==(const StringParameter &_instance) const | 
|---|
|  | 60 | { | 
|---|
|  | 61 | bool status = true; | 
|---|
|  | 62 | status = status && (ValueSet == _instance.ValueSet); | 
|---|
|  | 63 | if (ValueSet && _instance.ValueSet) | 
|---|
|  | 64 | status = status && (value == _instance.value); | 
|---|
|  | 65 | status = status && (Parameter::getName() == _instance.Parameter::getName()); | 
|---|
|  | 66 | return status; | 
|---|
|  | 67 | } | 
|---|
|  | 68 |  | 
|---|
|  | 69 | /** Implementation of clone function. | 
|---|
|  | 70 | * | 
|---|
|  | 71 | * @return copy of this instance with same value | 
|---|
|  | 72 | */ | 
|---|
|  | 73 | Parameter* StringParameter::clone() const | 
|---|
|  | 74 | { | 
|---|
|  | 75 | StringParameter *instance = new StringParameter(Parameter::getName(), get()); | 
|---|
|  | 76 | return instance; | 
|---|
|  | 77 | } | 
|---|
|  | 78 |  | 
|---|
|  | 79 | /** ValueInterface function implementation whether value is valid. | 
|---|
|  | 80 | * | 
|---|
|  | 81 | * \note we always return true as there is no invalid string | 
|---|
|  | 82 | * | 
|---|
|  | 83 | * @param _value value to test | 
|---|
|  | 84 | * @return true | 
|---|
|  | 85 | */ | 
|---|
|  | 86 | bool StringParameter::isValid(const std::string _value) const | 
|---|
|  | 87 | { | 
|---|
|  | 88 | return true; | 
|---|
|  | 89 | } | 
|---|
|  | 90 |  | 
|---|
|  | 91 | /** Getter for \a value. | 
|---|
|  | 92 | * | 
|---|
|  | 93 | * @return value | 
|---|
|  | 94 | */ | 
|---|
|  | 95 | const std::string StringParameter::get() const | 
|---|
|  | 96 | { | 
|---|
|  | 97 | ASSERT(ValueSet, | 
|---|
|  | 98 | ""); | 
|---|
|  | 99 | return value; | 
|---|
|  | 100 | } | 
|---|
|  | 101 |  | 
|---|
|  | 102 | /** Setter for \a value. | 
|---|
|  | 103 | * | 
|---|
|  | 104 | * @param _value value to set to | 
|---|
|  | 105 | */ | 
|---|
|  | 106 | void StringParameter::set(const std::string _value) | 
|---|
|  | 107 | { | 
|---|
|  | 108 | value = _value; | 
|---|
|  | 109 | ValueSet = true; | 
|---|
|  | 110 | } | 
|---|