use new API. kill old one.

This commit is contained in:
Mathieu Lacage
2011-08-03 10:04:56 -04:00
parent 10a4ade82a
commit aef38c492b
10 changed files with 67 additions and 127 deletions

View File

@@ -43,43 +43,40 @@ AttributeDefaultIterator::Iterate (void)
bool calledStart = false;
for (uint32_t j = 0; j < tid.GetAttributeN (); j++)
{
uint32_t flags = tid.GetAttributeFlags (j);
if (!(flags & TypeId::ATTR_CONSTRUCT))
struct TypeId::AttributeInformation info = tid.GetAttribute (j);
if (!(info.flags & TypeId::ATTR_CONSTRUCT))
{
// we can't construct the attribute, so, there is no
// initial value for the attribute
continue;
}
Ptr<const AttributeAccessor> accessor = tid.GetAttributeAccessor (j);
//No accessor, go to next attribute
if (accessor == 0)
if (info.accessor == 0)
{
continue;
}
if (!accessor->HasSetter ())
if (!info.accessor->HasSetter ())
{
//skip this attribute it doesn't have an setter
continue;
}
Ptr<const AttributeChecker> checker = tid.GetAttributeChecker (j);
if (checker == 0)
if (info.checker == 0)
{
//skip, it doesn't have a checker
continue;
}
Ptr<const AttributeValue> value = tid.GetAttributeInitialValue (j);
if (value == 0)
if (info.initialValue == 0)
{
//No value, check next attribute
continue;
}
Ptr<const ObjectVectorValue> vector = DynamicCast<const ObjectVectorValue> (value);
Ptr<const ObjectVectorValue> vector = DynamicCast<const ObjectVectorValue> (info.initialValue);
if (vector != 0)
{
//a vector value, won't take it
continue;
}
Ptr<const PointerValue> pointer = DynamicCast<const PointerValue> (value);
Ptr<const PointerValue> pointer = DynamicCast<const PointerValue> (info.initialValue);
if (pointer != 0)
{
//pointer value, won't take it
@@ -88,9 +85,9 @@ AttributeDefaultIterator::Iterate (void)
//We take only values, no pointers or vectors
if (!calledStart)
{
StartVisitTypeId (tid.GetName ());
StartVisitTypeId (info.name);
}
VisitAttribute (tid, tid.GetAttributeName (j), value->SerializeToString (checker), j);
VisitAttribute (tid, info.name, info.initialValue->SerializeToString (info.checker), j);
calledStart = true;
}
if (calledStart)

View File

@@ -203,17 +203,17 @@ AttributeIterator::DoIterate (Ptr<Object> object)
NS_LOG_DEBUG ("store " << tid.GetName ());
for (uint32_t i = 0; i < tid.GetAttributeN (); ++i)
{
Ptr<const AttributeChecker> checker = tid.GetAttributeChecker (i);
const PointerChecker *ptrChecker = dynamic_cast<const PointerChecker *> (PeekPointer (checker));
struct TypeId::AttributeInformation info = tid.GetAttribute(i);
const PointerChecker *ptrChecker = dynamic_cast<const PointerChecker *> (PeekPointer (info.checker));
if (ptrChecker != 0)
{
NS_LOG_DEBUG ("pointer attribute " << tid.GetAttributeName (i));
NS_LOG_DEBUG ("pointer attribute " << info.name);
PointerValue ptr;
object->GetAttribute (tid.GetAttributeName (i), ptr);
object->GetAttribute (info.name, ptr);
Ptr<Object> tmp = ptr.Get<Object> ();
if (tmp != 0)
{
StartVisitPointerAttribute (object, tid.GetAttributeName (i),
StartVisitPointerAttribute (object, info.name,
tmp);
m_examined.push_back (object);
DoIterate (tmp);
@@ -223,13 +223,13 @@ AttributeIterator::DoIterate (Ptr<Object> object)
continue;
}
// attempt to cast to an object vector.
const ObjectVectorChecker *vectorChecker = dynamic_cast<const ObjectVectorChecker *> (PeekPointer (checker));
const ObjectVectorChecker *vectorChecker = dynamic_cast<const ObjectVectorChecker *> (PeekPointer (info.checker));
if (vectorChecker != 0)
{
NS_LOG_DEBUG ("vector attribute " << tid.GetAttributeName (i));
NS_LOG_DEBUG ("vector attribute " << info.name);
ObjectVectorValue vector;
object->GetAttribute (tid.GetAttributeName (i), vector);
StartVisitArrayAttribute (object, tid.GetAttributeName (i), vector);
object->GetAttribute (info.name, vector);
StartVisitArrayAttribute (object, info.name, vector);
for (uint32_t j = 0; j < vector.GetN (); ++j)
{
NS_LOG_DEBUG ("vector attribute item " << j);
@@ -243,16 +243,14 @@ AttributeIterator::DoIterate (Ptr<Object> object)
EndVisitArrayAttribute ();
continue;
}
uint32_t flags = tid.GetAttributeFlags (i);
Ptr<const AttributeAccessor> accessor = tid.GetAttributeAccessor (i);
if ((flags & TypeId::ATTR_GET) && accessor->HasGetter () &&
(flags & TypeId::ATTR_SET) && accessor->HasSetter ())
if ((info.flags & TypeId::ATTR_GET) && info.accessor->HasGetter () &&
(info.flags & TypeId::ATTR_SET) && info.accessor->HasSetter ())
{
VisitAttribute (object, tid.GetAttributeName (i));
VisitAttribute (object, info.name);
}
else
{
NS_LOG_DEBUG ("could not store " << tid.GetAttributeName (i));
NS_LOG_DEBUG ("could not store " << info.name);
}
}
}

View File

@@ -62,7 +62,7 @@ AttributeList::~AttributeList ()
void
AttributeList::Set (std::string name, const AttributeValue &value)
{
struct TypeId::AttributeInfo info;
struct TypeId::AttributeInformation info;
bool ok = TypeId::LookupAttributeByFullName (name, &info);
if (!ok)
{
@@ -77,7 +77,7 @@ AttributeList::Set (std::string name, const AttributeValue &value)
bool
AttributeList::SetFailSafe (std::string name, const AttributeValue &value)
{
struct TypeId::AttributeInfo info;
struct TypeId::AttributeInformation info;
bool ok = TypeId::LookupAttributeByFullName (name, &info);
if (!ok)
{
@@ -89,7 +89,7 @@ AttributeList::SetFailSafe (std::string name, const AttributeValue &value)
void
AttributeList::SetWithTid (TypeId tid, std::string name, const AttributeValue & value)
{
struct TypeId::AttributeInfo info;
struct TypeId::AttributeInformation info;
bool ok = tid.LookupAttributeByName (name, &info);
if (!ok)
{
@@ -122,7 +122,7 @@ AttributeList::DoSetOne (Ptr<const AttributeChecker> checker, const AttributeVal
m_attributes.push_back (attr);
}
bool
AttributeList::DoSet (struct TypeId::AttributeInfo *info, const AttributeValue &value)
AttributeList::DoSet (struct TypeId::AttributeInformation *info, const AttributeValue &value)
{
if (info->checker == 0)
{
@@ -175,7 +175,8 @@ AttributeList::LookupAttributeFullNameByChecker (Ptr<const AttributeChecker> che
TypeId tid = TypeId::GetRegistered (i);
for (uint32_t j = 0; j < tid.GetAttributeN (); j++)
{
if (checker == tid.GetAttributeChecker (j))
struct TypeId::AttributeInformation info = tid.GetAttribute(j);
if (checker == info.checker)
{
return tid.GetAttributeFullName (j);
}
@@ -220,7 +221,7 @@ AttributeList::DeserializeFromString (std::string str)
else
{
std::string name = str.substr (cur, equal-cur);
struct TypeId::AttributeInfo info;
struct TypeId::AttributeInformation info;
if (!TypeId::LookupAttributeByFullName (name, &info))
{
NS_FATAL_ERROR ("Error while parsing serialized attribute: name does not exist: \"" << name << "\"");

View File

@@ -101,7 +101,7 @@ private:
bool DoSet (struct TypeId::AttributeInfo *info, const AttributeValue &param);
bool DoSet (struct TypeId::AttributeInformation *info, const AttributeValue &param);
void DoSetOne (Ptr<const AttributeChecker> checker, const AttributeValue &param);
std::string LookupAttributeFullNameByChecker (Ptr<const AttributeChecker> checker) const;

View File

@@ -157,10 +157,9 @@ CommandLine::PrintAttributes (std::string type) const
for (uint32_t i = 0; i < tid.GetAttributeN (); ++i)
{
std::cout << " --"<<tid.GetAttributeFullName (i)<<"=[";
Ptr<const AttributeChecker> checker = tid.GetAttributeChecker (i);
Ptr<const AttributeValue> initial = tid.GetAttributeInitialValue (i);
std::cout << initial->SerializeToString (checker) << "]: "
<< tid.GetAttributeHelp (i) << std::endl;
struct TypeId::AttributeInformation info = tid.GetAttribute (i);
std::cout << info.initialValue->SerializeToString (info.checker) << "]: "
<< info.help << std::endl;
}
}

View File

@@ -377,7 +377,7 @@ Resolver::DoResolve (std::string path, Ptr<Object> root)
{
// this is a normal attribute.
TypeId tid = root->GetInstanceTypeId ();
struct TypeId::AttributeInfo info;
struct TypeId::AttributeInformation info;
if (!tid.LookupAttributeByName (item, &info))
{
NS_LOG_DEBUG ("Requested item="<<item<<" does not exist on path="<<GetResolvedPath ());

View File

@@ -158,14 +158,14 @@ ObjectBase::ConstructSelf (const AttributeList &attributes)
}
bool
ObjectBase::DoSet (Ptr<const AttributeAccessor> spec,
ObjectBase::DoSet (Ptr<const AttributeAccessor> accessor,
Ptr<const AttributeChecker> checker,
const AttributeValue &value)
{
bool ok = checker->Check (value);
if (ok)
{
ok = spec->Set (this, value);
ok = accessor->Set (this, value);
return ok;
}
// attempt to convert to string
@@ -186,13 +186,13 @@ ObjectBase::DoSet (Ptr<const AttributeAccessor> spec,
{
return false;
}
ok = spec->Set (this, *v);
ok = accessor->Set (this, *v);
return ok;
}
void
ObjectBase::SetAttribute (std::string name, const AttributeValue &value)
{
struct TypeId::AttributeInfo info;
struct TypeId::AttributeInformation info;
TypeId tid = GetInstanceTypeId ();
if (!tid.LookupAttributeByName (name, &info))
{
@@ -211,7 +211,7 @@ ObjectBase::SetAttribute (std::string name, const AttributeValue &value)
bool
ObjectBase::SetAttributeFailSafe (std::string name, const AttributeValue &value)
{
struct TypeId::AttributeInfo info;
struct TypeId::AttributeInformation info;
TypeId tid = GetInstanceTypeId ();
if (!tid.LookupAttributeByName (name, &info))
{
@@ -228,7 +228,7 @@ ObjectBase::SetAttributeFailSafe (std::string name, const AttributeValue &value)
void
ObjectBase::GetAttribute (std::string name, AttributeValue &value) const
{
struct TypeId::AttributeInfo info;
struct TypeId::AttributeInformation info;
TypeId tid = GetInstanceTypeId ();
if (!tid.LookupAttributeByName (name, &info))
{
@@ -262,7 +262,7 @@ ObjectBase::GetAttribute (std::string name, AttributeValue &value) const
bool
ObjectBase::GetAttributeFailSafe (std::string name, AttributeValue &value) const
{
struct TypeId::AttributeInfo info;
struct TypeId::AttributeInformation info;
TypeId tid = GetInstanceTypeId ();
if (!tid.LookupAttributeByName (name, &info))
{

View File

@@ -459,7 +459,7 @@ TypeId::LookupByNameFailSafe (std::string name, TypeId *tid)
}
bool
TypeId::LookupAttributeByFullName (std::string fullName, struct TypeId::AttributeInfo *info)
TypeId::LookupAttributeByFullName (std::string fullName, struct TypeId::AttributeInformation *info)
{
std::string::size_type pos = fullName.rfind ("::");
if (pos == std::string::npos)
@@ -488,7 +488,7 @@ TypeId::GetRegistered (uint32_t i)
}
bool
TypeId::LookupAttributeByName (std::string name, struct TypeId::AttributeInfo *info) const
TypeId::LookupAttributeByName (std::string name, struct TypeId::AttributeInformation *info) const
{
TypeId tid;
TypeId nextTid = *this;
@@ -496,13 +496,10 @@ TypeId::LookupAttributeByName (std::string name, struct TypeId::AttributeInfo *i
tid = nextTid;
for (uint32_t i = 0; i < tid.GetAttributeN (); i++)
{
std::string paramName = tid.GetAttributeName (i);
if (paramName == name)
struct TypeId::AttributeInformation tmp = tid.GetAttribute(i);
if (tmp.name == name)
{
info->accessor = tid.GetAttributeAccessor (i);
info->flags = tid.GetAttributeFlags (i);
info->initialValue = tid.GetAttributeInitialValue (i);
info->checker = tid.GetAttributeChecker (i);
*info = tmp;
return true;
}
}
@@ -643,27 +640,6 @@ TypeId::GetAttributeInitialValue (uint32_t i) const
Ptr<const AttributeValue> value = Singleton<IidManager>::Get ()->GetAttributeInitialValue (m_tid, i);
return value;
}
Ptr<const AttributeAccessor>
TypeId::GetAttributeAccessor (uint32_t i) const
{
// Used exclusively by the Object class.
Ptr<const AttributeAccessor> accessor = Singleton<IidManager>::Get ()->GetAttributeAccessor (m_tid, i);
return accessor;
}
uint32_t
TypeId::GetAttributeFlags (uint32_t i) const
{
// Used exclusively by the Object class.
uint32_t flags = Singleton<IidManager>::Get ()->GetAttributeFlags (m_tid, i);
return flags;
}
Ptr<const AttributeChecker>
TypeId::GetAttributeChecker (uint32_t i) const
{
// Used exclusively by the Object class.
Ptr<const AttributeChecker> checker = Singleton<IidManager>::Get ()->GetAttributeChecker (m_tid, i);
return checker;
}
uint32_t
TypeId::GetTraceSourceN (void) const

View File

@@ -176,21 +176,6 @@ public:
* is initialized.
*/
Ptr<const AttributeValue> GetAttributeInitialValue (uint32_t i) const;
/**
* \param i index into attribute array.
* \returns the flags associated to the requested attribute.
*/
uint32_t GetAttributeFlags (uint32_t i) const;
/**
* \param i index into attribute array.
* \returns the checker associated to the requested attribute.
*/
Ptr<const AttributeChecker> GetAttributeChecker (uint32_t i) const;
/**
* \param i index into attribute array.
* \returns the accessor associated to the requested attribute.
*/
Ptr<const AttributeAccessor> GetAttributeAccessor (uint32_t i) const;
/**
* \returns a callback which can be used to instanciate an object
@@ -318,26 +303,13 @@ public:
TypeId HideFromDocumentation (void);
/**
* \brief store together a set of attribute properties.
*/
struct AttributeInfo {
// The accessor associated to the attribute.
Ptr<const AttributeAccessor> accessor;
// The initial value associated to the attribute.
Ptr<const AttributeValue> initialValue;
// The set of access control flags associated to the attribute.
uint32_t flags;
// The checker associated to the attribute.
Ptr<const AttributeChecker> checker;
};
/**
* \param name the name of the requested attribute
* \param info a pointer to the TypeId::AttributeInfo data structure
* \param info a pointer to the TypeId::AttributeInformation data structure
* where the result value of this method will be stored.
* \returns true if the requested attribute could be found, false otherwise.
*/
bool LookupAttributeByName (std::string name, struct AttributeInfo *info) const;
bool LookupAttributeByName (std::string name, struct AttributeInformation *info) const;
/**
* \param name the name of the requested trace source
* \returns the trace source accessor which can be used to connect and disconnect
@@ -350,11 +322,11 @@ public:
/**
* \param fullName the full name of the requested attribute
* \param info a pointer to the TypeId::AttributeInfo data structure
* \param info a pointer to the TypeId::AttributeInformation data structure
* where the result value of this method will be stored.
* \returns the Accessor associated to the requested attribute
*/
static bool LookupAttributeByFullName (std::string fullName, struct AttributeInfo *info);
static bool LookupAttributeByFullName (std::string fullName, struct AttributeInformation *info);
/**
* \returns the internal integer which uniquely identifies this

View File

@@ -19,32 +19,29 @@ PrintAttributes (TypeId tid, std::ostream &os)
os << "<ul>"<<std::endl;
for (uint32_t j = 0; j < tid.GetAttributeN (); j++)
{
os << "<li><b>" << tid.GetAttributeName (j) << "</b>: "
<< tid.GetAttributeHelp (j) << std::endl;
Ptr<const AttributeChecker> checker = tid.GetAttributeChecker (j);
struct TypeId::AttributeInformation info = tid.GetAttribute(j);
os << "<li><b>" << info.name << "</b>: "
<< info.help << std::endl;
os << " <ul>" << std::endl
<< " <li>Set with class: \\ref " << checker->GetValueTypeName () << "</li>" << std::endl;
if (checker->HasUnderlyingTypeInformation ())
<< " <li>Set with class: \\ref " << info.checker->GetValueTypeName () << "</li>" << std::endl;
if (info.checker->HasUnderlyingTypeInformation ())
{
os << " <li>Underlying type: \\ref " << checker->GetUnderlyingTypeInformation () << "</li>" << std::endl;
os << " <li>Underlying type: \\ref " << info.checker->GetUnderlyingTypeInformation () << "</li>" << std::endl;
}
uint32_t flags = tid.GetAttributeFlags (j);
Ptr<const AttributeAccessor> accessor = tid.GetAttributeAccessor (j);
if (flags & TypeId::ATTR_CONSTRUCT && accessor->HasSetter ())
if (info.flags & TypeId::ATTR_CONSTRUCT && info.accessor->HasSetter ())
{
Ptr<const AttributeValue> initial = tid.GetAttributeInitialValue (j);
os << " <li>Initial value: " << initial->SerializeToString (checker) << "</li>" << std::endl;
os << " <li>Initial value: " << info.initialValue->SerializeToString (info.checker) << "</li>" << std::endl;
}
os << " <li>Flags: ";
if (flags & TypeId::ATTR_CONSTRUCT && accessor->HasSetter ())
if (info.flags & TypeId::ATTR_CONSTRUCT && info.accessor->HasSetter ())
{
os << "construct ";
}
if (flags & TypeId::ATTR_SET && accessor->HasSetter ())
if (info.flags & TypeId::ATTR_SET && info.accessor->HasSetter ())
{
os << "write ";
}
if (flags & TypeId::ATTR_GET && accessor->HasGetter ())
if (info.flags & TypeId::ATTR_GET && info.accessor->HasGetter ())
{
os << "read ";
}
@@ -173,12 +170,12 @@ StaticInformation::DoGather (TypeId tid)
RecordOutput (tid);
for (uint32_t i = 0; i < tid.GetAttributeN (); ++i)
{
Ptr<const AttributeChecker> checker = tid.GetAttributeChecker (i);
const PointerChecker *ptrChecker = dynamic_cast<const PointerChecker *> (PeekPointer (checker));
struct TypeId::AttributeInformation info = tid.GetAttribute(i);
const PointerChecker *ptrChecker = dynamic_cast<const PointerChecker *> (PeekPointer (info.checker));
if (ptrChecker != 0)
{
TypeId pointee = ptrChecker->GetPointeeTypeId ();
m_currentPath.push_back (tid.GetAttributeName (i));
m_currentPath.push_back (info.name);
m_alreadyProcessed.push_back (tid);
DoGather (pointee);
m_alreadyProcessed.pop_back ();
@@ -186,11 +183,11 @@ StaticInformation::DoGather (TypeId tid)
continue;
}
// attempt to cast to an object vector.
const ObjectVectorChecker *vectorChecker = dynamic_cast<const ObjectVectorChecker *> (PeekPointer (checker));
const ObjectVectorChecker *vectorChecker = dynamic_cast<const ObjectVectorChecker *> (PeekPointer (info.checker));
if (vectorChecker != 0)
{
TypeId item = vectorChecker->GetItemTypeId ();
m_currentPath.push_back (tid.GetAttributeName (i) + "/[i]");
m_currentPath.push_back (info.name + "/[i]");
m_alreadyProcessed.push_back (tid);
DoGather (item);
m_alreadyProcessed.pop_back ();