Files
unison/src/core/model/attribute.cc

106 lines
2.3 KiB
C++
Raw Normal View History

2008-03-10 00:38:48 +01:00
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2008 INRIA
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
*/
2008-02-20 21:45:42 +01:00
#include "attribute.h"
2008-01-31 15:10:21 +01:00
#include "log.h"
#include "fatal-error.h"
2011-08-03 13:58:10 -04:00
#include "string.h"
2008-01-31 15:10:21 +01:00
#include <sstream>
2008-01-30 17:28:18 +01:00
namespace ns3 {
NS_LOG_COMPONENT_DEFINE ("AttributeValue");
2008-02-20 21:17:34 +01:00
AttributeValue::AttributeValue ()
2011-05-13 14:52:27 -04:00
{
}
2008-02-20 21:17:34 +01:00
AttributeValue::~AttributeValue ()
2011-05-13 14:52:27 -04:00
{
}
2008-01-31 15:10:21 +01:00
AttributeAccessor::AttributeAccessor ()
2011-05-13 14:52:27 -04:00
{
}
AttributeAccessor::~AttributeAccessor ()
2011-05-13 14:52:27 -04:00
{
}
2008-01-31 15:10:21 +01:00
AttributeChecker::AttributeChecker ()
2011-05-13 14:52:27 -04:00
{
}
AttributeChecker::~AttributeChecker ()
2011-05-13 14:52:27 -04:00
{
}
2011-08-03 13:58:10 -04:00
Ptr<AttributeValue>
AttributeChecker::CreateValidValue (const AttributeValue &value) const
{
NS_LOG_FUNCTION (this << &value);
2011-08-03 13:58:10 -04:00
if (Check (value))
{
return value.Copy ();
}
// attempt to convert to string.
const StringValue *str = dynamic_cast<const StringValue *> (&value);
if (str == 0)
{
return 0;
}
// attempt to convert back to value.
Ptr<AttributeValue> v = Create ();
bool ok = v->DeserializeFromString (str->Get (), this);
if (!ok)
{
return 0;
}
ok = Check (*v);
if (!ok)
{
return 0;
}
return v;
}
EmptyAttributeValue::EmptyAttributeValue ()
2011-05-13 14:52:27 -04:00
{
NS_LOG_FUNCTION (this);
2011-05-13 14:52:27 -04:00
}
Ptr<AttributeValue>
EmptyAttributeValue::Copy (void) const
2008-01-31 15:10:21 +01:00
{
NS_LOG_FUNCTION (this);
return Create<EmptyAttributeValue> ();
2008-01-31 15:10:21 +01:00
}
2011-05-13 14:52:27 -04:00
std::string
EmptyAttributeValue::SerializeToString (Ptr<const AttributeChecker> checker) const
2008-01-31 15:10:21 +01:00
{
NS_LOG_FUNCTION (this << checker);
return "";
2008-01-31 15:10:21 +01:00
}
2011-05-13 14:52:27 -04:00
bool
EmptyAttributeValue::DeserializeFromString (std::string value, Ptr<const AttributeChecker> checker)
2008-01-31 15:10:21 +01:00
{
NS_LOG_FUNCTION (this << value << checker);
return true;
2008-01-31 15:10:21 +01:00
}
2008-01-30 17:28:18 +01:00
} // namespace ns3