Commit 0a985294 authored by Emmanuel Christophe's avatar Emmanuel Christophe
Browse files

ENH: adding accessor

parent 0ddb263b
......@@ -44,6 +44,9 @@ public:
/** Standard class typedefs. */
typedef ImageKeywordlist Self;
virtual const char *GetNameOfClass() const
{return "ImageKeywordlist";}
typedef std::map<ossimString, ossimString> KeywordlistMap;
void SetKeywordlist(const ossimKeywordlist& kwl)
......
......@@ -42,8 +42,9 @@ VectorDataKeywordlist
}
}
void VectorDataKeywordlist::
AddField(OGRFieldDefn* fieldDefn, OGRField* field)
void
VectorDataKeywordlist
::AddField(OGRFieldDefn* fieldDefn, OGRField* field)
{
FieldType newField;
newField.first = fieldDefn;
......@@ -55,9 +56,55 @@ void VectorDataKeywordlist::
m_FieldList.push_back(CopyOgrField(newField));
};
std::string
VectorDataKeywordlist
::GetFieldAsString(std::string key) const
{
for (unsigned int i = 0; i < m_FieldList.size(); ++i)
{
if (key.compare(m_FieldList[i].first->GetNameRef()) == 0)
{
return m_FieldList[i].second.String;
}
}
return "";
}
bool
VectorDataKeywordlist
::HasField(std::string key) const
{
for (unsigned int i = 0; i < m_FieldList.size(); ++i)
{
if (key.compare(m_FieldList[i].first->GetNameRef()) == 0)
{
return true;
}
}
return false;
}
VectorDataKeywordlist::FieldType
VectorDataKeywordlist
::GetNthField(unsigned int index) const
{
if (index > m_FieldList.size())
{
itkExceptionMacro(<<" Accessing out-of-range metadata ");
}
return m_FieldList[index];
}
unsigned int
VectorDataKeywordlist
::GetNumberOfFields() const
{
return m_FieldList.size();
}
void
VectorDataKeywordlist::
operator=(const Self& p)
VectorDataKeywordlist
::operator=(const Self& p)
{
for (unsigned int i = 0; i < p.m_FieldList.size(); ++i)
{
......@@ -66,15 +113,15 @@ VectorDataKeywordlist::
}
void
VectorDataKeywordlist::
Print(std::ostream& os, itk::Indent indent) const
VectorDataKeywordlist
::Print(std::ostream& os, itk::Indent indent) const
{
this->PrintSelf(os, indent.GetNextIndent());
}
void
VectorDataKeywordlist::
PrintSelf(std::ostream& os, itk::Indent indent) const
VectorDataKeywordlist
::PrintSelf(std::ostream& os, itk::Indent indent) const
{
os << indent << " VectorData Keyword list: ";
os << indent << " - Size: " << m_FieldList.size() << std::endl;
......@@ -85,8 +132,8 @@ VectorDataKeywordlist::
}
std::string
VectorDataKeywordlist::
PrintField(FieldType field) const
VectorDataKeywordlist
::PrintField(FieldType field) const
{
std::stringstream output;
output << std::setprecision(15);
......@@ -165,8 +212,8 @@ VectorDataKeywordlist::
VectorDataKeywordlist::FieldType
VectorDataKeywordlist::
CopyOgrField(FieldType field)
VectorDataKeywordlist
::CopyOgrField(FieldType field)
{
FieldType outField;
outField.first = new OGRFieldDefn(field.first);
......
......@@ -33,7 +33,7 @@ namespace otb
* a vector object. This information is retrieved from the input file (a
* shapefile for example) and propagated along the pipeline with the object.
*
* This is the equivalent of the otbOssimKeywordlist class but for OGR information.
* This is the equivalent of the otbImageKeywordlist class but for OGR information.
*
* \todo add the accessor to enable modifying/updating the data.
*
......@@ -48,12 +48,44 @@ class VectorDataKeywordlist
typedef std::pair<OGRFieldDefn*,OGRField> FieldType;
typedef std::vector< FieldType > FieldListType;
virtual const char *GetNameOfClass() const
{return "VectorDataKeywordlist";}
void AddField(OGRFieldDefn* fieldDefn, OGRField* field);
/**
* Returns the value associated with a field name.
* \param key The name of the field.
* \return The value of the field. A default value is retuned if the key was not found.
*/
std::string GetFieldAsString(std::string key) const;
/**
* \return True if the node contains the field named after the given key.
* \param key The name of the field.
*/
bool HasField(std::string key) const;
/**
* \return the nth field of the node as a std::pair of (key,value).
* \param index the index of the field to return.
*/
FieldType GetNthField(unsigned int index) const;
/**
* \return the number of fields in the node.
*/
unsigned int GetNumberOfFields() const;
/**
* Print the keyword list
*/
virtual void Print(std::ostream& os, itk::Indent indent=0) const;
/** Constructor */
VectorDataKeywordlist();
/** Destructor */
virtual ~VectorDataKeywordlist();
/** Constructor by copy (deep copy)*/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment