00001 // Torc - Copyright 2011 University of Southern California. All Rights Reserved. 00002 // $HeadURL: https://svn.east.isi.edu/torc/trunk/src/torc/physical/Config.hpp $ 00003 // $Id: Config.hpp 479 2011-06-05 04:04:54Z nsteiner $ 00004 00005 // This program is free software: you can redistribute it and/or modify it under the terms of the 00006 // GNU General Public License as published by the Free Software Foundation, either version 3 of the 00007 // License, or (at your option) any later version. 00008 // 00009 // This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 00010 // without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 00011 // the GNU General Public License for more details. 00012 // 00013 // You should have received a copy of the GNU General Public License along with this program. If 00014 // not, see <http://www.gnu.org/licenses/>. 00015 00016 /// \file 00017 /// \brief Header for the Config class. 00018 00019 #ifndef TORC_PHYSICAL_CONFIG_HPP 00020 #define TORC_PHYSICAL_CONFIG_HPP 00021 00022 #include "torc/physical/XilinxPhysicalTypes.hpp" 00023 #include "torc/physical/Named.hpp" 00024 00025 namespace torc { 00026 namespace physical { 00027 00028 // forward declaration of our unit test class within its namespace 00029 namespace physical { class ConfigUnitTest; } 00030 00031 /// \brief Configuration. A {name:value} pair. 00032 /// \details Config elements typically live in a ConfigMap, and by inheritance, in Design, 00033 /// Module, Instance, and Net objects. Within a ConfigMap, a setting name acts as a key 00034 /// that points to a Config, together forming the standard {setting:name:value} triplet. 00035 /// \note The name mentioned here is a user-specified name stemming from the design. It is not 00036 /// the configuration setting name. For example, in configuration "DFF:blink:#FF", "DFF" 00037 /// is the specified setting, "blink" is the name that the design assigns to the 00038 /// corresponding resource, and "#FF" is the value to which "DFF" is set. 00039 class Config : public Named { 00040 // friends 00041 /// \brief The ConfigMap class has direct access to our internals. 00042 friend class ConfigMap; 00043 /// \brief Our unit test has direct access to our internals. 00044 friend class torc::physical::physical::ConfigUnitTest; 00045 protected: 00046 // types 00047 /// \brief Imported type name. 00048 typedef std::string string; 00049 // static variables 00050 /// \brief Default configuration name. 00051 static const char* sConfigDefaultName; 00052 /// \brief Default configuration value. 00053 static const char* sConfigDefaultValue; 00054 // members 00055 /// \brief The configuration setting value. 00056 /// \todo Consider typing mValue to something like SettingValueString. 00057 string mValue; 00058 /// \brief The sequence in which the configuration was created. 00059 /// \details This is used by the XDL exporter to preserve the original order in cases where 00060 /// multiple configurations exist for the same setting name. 00061 SequenceIndex mOrder; 00062 // accessors 00063 /// \brief Set the sequence index for this configuration. 00064 /// \param inOrder The new sequence index. 00065 void setOrder(SequenceIndex inOrder) { mOrder = inOrder; } 00066 // constructors 00067 /// \brief Protected copy constructor. This constructor allows the caller to specify the 00068 /// sequence index. 00069 /// \param inName The configuration name. The is a user-specified name, not a setting name. 00070 /// \param inValue The configuration value. 00071 /// \param inOrder The sequence index. 00072 Config(const string& inName, const string& inValue, SequenceIndex inOrder) 00073 : Named(inName), mValue(inValue), mOrder(inOrder) {} 00074 public: 00075 // constructors 00076 /// \brief Null constructor required by collections. 00077 Config(void) 00078 : Named(sConfigDefaultName), mValue(sConfigDefaultValue), mOrder(eSequenceIndexNone) {} 00079 /// \brief Standard constructor. 00080 /// \param inName The configuration name. The is a user-specified name, not a setting name. 00081 /// \param inValue The configuration value. 00082 Config(const string& inName, const string& inValue) 00083 : Named(inName), mValue(inValue), mOrder(eSequenceIndexNone) {} 00084 // accessors 00085 /// \brief Return the configuration value. 00086 const string& getValue(void) const { return mValue; } 00087 /// \brief Return the configuration sequence index. 00088 SequenceIndex getOrder(void) const { return mOrder; } 00089 /// \brief Set the configuration value. 00090 void setValue(const string& inValue) { mValue = inValue; } 00091 /// \brief Sets the object name. 00092 /// \details Config names can be changed arbitrarily, but other Named subclasses require 00093 /// more complex semantics to prevent name collisions. 00094 void setName(const string& inName) { mName = inName; } 00095 // operators 00096 /// \brief Comparison operator. 00097 /// \returns true if specified configuration matches this one in both name and value, or 00098 /// false otherwise. 00099 bool operator ==(const Config& rhs) const 00100 { return mName == rhs.mName && mValue == rhs.mValue; } 00101 }; 00102 00103 } // namespace physical 00104 } // namespace torc 00105 00106 #endif // TORC_PHYSICAL_CONFIG_HPP