Skip to content
Snippets Groups Projects
Commit 0a985294 authored by Emmanuel Christophe's avatar Emmanuel Christophe
Browse files

ENH: adding accessor

parent 0ddb263b
No related branches found
No related tags found
No related merge requests found
...@@ -44,6 +44,9 @@ public: ...@@ -44,6 +44,9 @@ public:
/** Standard class typedefs. */ /** Standard class typedefs. */
typedef ImageKeywordlist Self; typedef ImageKeywordlist Self;
virtual const char *GetNameOfClass() const
{return "ImageKeywordlist";}
typedef std::map<ossimString, ossimString> KeywordlistMap; typedef std::map<ossimString, ossimString> KeywordlistMap;
void SetKeywordlist(const ossimKeywordlist& kwl) void SetKeywordlist(const ossimKeywordlist& kwl)
......
...@@ -42,8 +42,9 @@ VectorDataKeywordlist ...@@ -42,8 +42,9 @@ VectorDataKeywordlist
} }
} }
void VectorDataKeywordlist:: void
AddField(OGRFieldDefn* fieldDefn, OGRField* field) VectorDataKeywordlist
::AddField(OGRFieldDefn* fieldDefn, OGRField* field)
{ {
FieldType newField; FieldType newField;
newField.first = fieldDefn; newField.first = fieldDefn;
...@@ -55,9 +56,55 @@ void VectorDataKeywordlist:: ...@@ -55,9 +56,55 @@ void VectorDataKeywordlist::
m_FieldList.push_back(CopyOgrField(newField)); 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 void
VectorDataKeywordlist:: VectorDataKeywordlist
operator=(const Self& p) ::operator=(const Self& p)
{ {
for (unsigned int i = 0; i < p.m_FieldList.size(); ++i) for (unsigned int i = 0; i < p.m_FieldList.size(); ++i)
{ {
...@@ -66,15 +113,15 @@ VectorDataKeywordlist:: ...@@ -66,15 +113,15 @@ VectorDataKeywordlist::
} }
void void
VectorDataKeywordlist:: VectorDataKeywordlist
Print(std::ostream& os, itk::Indent indent) const ::Print(std::ostream& os, itk::Indent indent) const
{ {
this->PrintSelf(os, indent.GetNextIndent()); this->PrintSelf(os, indent.GetNextIndent());
} }
void void
VectorDataKeywordlist:: VectorDataKeywordlist
PrintSelf(std::ostream& os, itk::Indent indent) const ::PrintSelf(std::ostream& os, itk::Indent indent) const
{ {
os << indent << " VectorData Keyword list: "; os << indent << " VectorData Keyword list: ";
os << indent << " - Size: " << m_FieldList.size() << std::endl; os << indent << " - Size: " << m_FieldList.size() << std::endl;
...@@ -85,8 +132,8 @@ VectorDataKeywordlist:: ...@@ -85,8 +132,8 @@ VectorDataKeywordlist::
} }
std::string std::string
VectorDataKeywordlist:: VectorDataKeywordlist
PrintField(FieldType field) const ::PrintField(FieldType field) const
{ {
std::stringstream output; std::stringstream output;
output << std::setprecision(15); output << std::setprecision(15);
...@@ -165,8 +212,8 @@ VectorDataKeywordlist:: ...@@ -165,8 +212,8 @@ VectorDataKeywordlist::
VectorDataKeywordlist::FieldType VectorDataKeywordlist::FieldType
VectorDataKeywordlist:: VectorDataKeywordlist
CopyOgrField(FieldType field) ::CopyOgrField(FieldType field)
{ {
FieldType outField; FieldType outField;
outField.first = new OGRFieldDefn(field.first); outField.first = new OGRFieldDefn(field.first);
......
...@@ -33,7 +33,7 @@ namespace otb ...@@ -33,7 +33,7 @@ namespace otb
* a vector object. This information is retrieved from the input file (a * a vector object. This information is retrieved from the input file (a
* shapefile for example) and propagated along the pipeline with the object. * 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. * \todo add the accessor to enable modifying/updating the data.
* *
...@@ -48,12 +48,44 @@ class VectorDataKeywordlist ...@@ -48,12 +48,44 @@ class VectorDataKeywordlist
typedef std::pair<OGRFieldDefn*,OGRField> FieldType; typedef std::pair<OGRFieldDefn*,OGRField> FieldType;
typedef std::vector< FieldType > FieldListType; typedef std::vector< FieldType > FieldListType;
virtual const char *GetNameOfClass() const
{return "VectorDataKeywordlist";}
void AddField(OGRFieldDefn* fieldDefn, OGRField* field); 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; virtual void Print(std::ostream& os, itk::Indent indent=0) const;
/** Constructor */
VectorDataKeywordlist(); VectorDataKeywordlist();
/** Destructor */
virtual ~VectorDataKeywordlist(); virtual ~VectorDataKeywordlist();
/** Constructor by copy (deep copy)*/ /** Constructor by copy (deep copy)*/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment