newspeoplefor developersdocumentationdownloads

attributecontainer.cc

Go to the documentation of this file.
00001 //------------------------------------------------------------------------------
00002 //  db/attributecontainer.h
00003 //  (C) 2005 Radon Labs GmbH
00004 //------------------------------------------------------------------------------
00005 #include "db/attributecontainer.h"
00006 
00007 namespace Db
00008 {
00009 
00010 //------------------------------------------------------------------------------
00013 AttributeContainer::AttributeContainer() :
00014     attrs(32, 64)
00015 {
00016     // empty
00017 }
00018 
00019 //------------------------------------------------------------------------------
00022 AttributeContainer::~AttributeContainer()
00023 {
00024     // empty
00025 }
00026 
00027 //------------------------------------------------------------------------------
00035 int
00036 AttributeContainer::FindAttrIndex(const Attr::AttributeID& attrId) const
00037 {
00038     int i;
00039     int num = this->attrs.Size();
00040     for (i = 0; i < num; i++)
00041     {
00042         if (this->attrs[i].GetAttributeID() == attrId)
00043         {
00044             return i;
00045         }
00046     } 
00047     return -1;
00048 }
00049 
00050 //------------------------------------------------------------------------------
00054 bool
00055 AttributeContainer::HasAttr(const Attr::AttributeID& id) const
00056 {
00057     return (-1 != this->FindAttrIndex(id));
00058 }
00059 
00060 //------------------------------------------------------------------------------
00067 void
00068 AttributeContainer::SetAttr(const Attribute& attr)
00069 {
00070     int attrIndex = this->FindAttrIndex(attr.GetAttributeID());
00071     if (-1 == attrIndex)
00072     {
00073         this->attrs.Append(attr);
00074     }
00075     else
00076     {
00077         // overwrite existing attribute, but make sure they're of the same type
00078         n_assert2(attr.GetType() == this->attrs[attrIndex].GetType(), attr.GetName().Get());
00079         this->attrs[attrIndex].SetValue(attr.GetValue());
00080     }
00081 }
00082 
00083 //------------------------------------------------------------------------------
00088 const Attribute&
00089 AttributeContainer::GetAttr(const Attr::AttributeID& attrId) const
00090 {
00091     n_assert( attrId.IsValid() );
00092     int attrIndex = this->FindAttrIndex(attrId);
00093     if (-1 != attrIndex)
00094     {
00095         return this->attrs[attrIndex];
00096     }
00097     else
00098     {
00099         n_error("Db::AttributeContainer::GetAttr(): attr '%s' not found!", attrId.GetName().Get());
00100         return this->attrs[0]; // silence the compiler
00101     }
00102 }
00103 
00104 //------------------------------------------------------------------------------
00108 const nArray<Attribute>&
00109 AttributeContainer::GetAttrs() const
00110 {
00111     return this->attrs;
00112 }
00113 
00114 //------------------------------------------------------------------------------
00118 void
00119 AttributeContainer::Clear()
00120 {
00121     this->attrs.Clear();
00122 }
00123 
00124 };

Copyright © 1999-2005 by the contributing authors. Ideas, requests, problems: Send feedback.