Commit e875eebb authored by Julien Osman's avatar Julien Osman

ENH: Use reference parameters instead of copy parameters for strings

parent 9c0709c5
......@@ -21,8 +21,6 @@
#ifndef otbGeomMetadataSupplier_h
#define otbGeomMetadataSupplier_h
#include <fstream>
#include <boost/algorithm/string.hpp>
#include <boost/any.hpp>
#include "OTBMetadataExport.h"
......@@ -58,9 +56,9 @@ public:
* @param band not used
* @return The value corresponding to path. Empty string if not found.
*/
std::string GetMetadataValue(const std::string path, bool& hasValue, int band=1) const override;
std::string GetMetadataValue(std::string const& path, bool& hasValue, int band=1) const override;
std::string GetResourceFile(std::string="") const override;
std::string GetResourceFile(std::string const& s="") const override;
int GetNbBands() const override;
......@@ -76,7 +74,7 @@ public:
*
* @return A std::string
*/
std::string PrintSelf();
std::string PrintSelf() const;
protected:
/**
......
......@@ -47,7 +47,7 @@ public:
class OTBMetadata_EXPORT MetadataSupplierInterface
{
public:
virtual std::string GetResourceFile(std::string="") const = 0;
virtual std::string GetResourceFile(std::string const& ="") const = 0;
virtual std::vector<std::string> GetResourceFiles() const
{
return std::vector<std::string>{this->GetResourceFile()};
......@@ -58,14 +58,14 @@ public:
* depends on the specific implementation. Returns empty string when path is not found,
* and hasValue is set to False.
* If band >= 0, the metadata value is looked in the specified band*/
virtual std::string GetMetadataValue(const std::string path, bool& hasValue, int band=-1) const = 0;
virtual std::string GetMetadataValue(std::string const& path, bool& hasValue, int band=-1) const = 0;
bool HasValue(std::string path, int band=-1);
bool HasValue(std::string const& path, int band=-1);
virtual int GetNbBands() const = 0;
// utility functions
template <typename T> T GetAs(std::string path, int band=-1) const
template <typename T> T GetAs(std::string const& path, int band=-1) const
{
bool hasValue;
std::string ret = GetMetadataValue(path, hasValue, band);
......@@ -86,7 +86,7 @@ public:
/** Parse a metadata value to a std::vector,
* If size>=0, then the final std::vector size is checked and an exception
* is raised if it doesn't match the given size.*/
template < typename T> std::vector<T> GetAsVector(std::string path, const char sep=' ', int size=-1, int band=-1) const
template < typename T> std::vector<T> GetAsVector(std::string const& path, char sep=' ', int size=-1, int band=-1) const
{
bool hasValue;
std::string ret = GetMetadataValue(path, hasValue, band);
......
......@@ -54,7 +54,7 @@ public:
* @param band not used
* @return The value corresponding to path. Empty string if not found.
*/
std::string GetMetadataValue(const std::string path, bool& hasValue, int band=1) const override;
std::string GetMetadataValue(std::string const& path, bool& hasValue, int band=1) const override;
/**
* @brief Get the first metadata value corresponding to a given path
......@@ -63,7 +63,7 @@ public:
* @param hasValue True if path is found
* @return The value corresponding to path. Empty string if not found.
*/
std::string GetFirstMetadataValue(const std::string paths, bool& hasValue) const;
std::string GetFirstMetadataValue(std::string const& paths, bool& hasValue) const;
/**
* @brief Get the metadata value corresponding to a given path
......@@ -80,7 +80,7 @@ public:
* @return The value corresponding to path.
* @raises otb::Error if path not found
*/
template <typename T> T GetFirstAs(const std::string &path) const
template <typename T> T GetFirstAs(std::string const& path) const
{
bool hasValue;
std::string ret = GetFirstMetadataValue(path, hasValue);
......@@ -98,7 +98,7 @@ public:
}
}
std::string GetResourceFile(std::string="") const override;
std::string GetResourceFile(std::string const& s="") const override;
int GetNbBands() const override;
......
......@@ -20,7 +20,8 @@
#include <iomanip>
#include <iostream>
#include<boost/algorithm/string.hpp>
#include <fstream>
#include <boost/algorithm/string.hpp>
#include "otbGeomMetadataSupplier.h"
#include "otbMetaDataKey.h"
......@@ -29,13 +30,13 @@
namespace otb
{
GeomMetadataSupplier::GeomMetadataSupplier(const std::string & fileName)
GeomMetadataSupplier::GeomMetadataSupplier(std::string const& fileName)
: m_FileName(fileName)
{
this->ReadGeomFile();
}
std::string GeomMetadataSupplier::GetMetadataValue(const std::string path, bool& hasValue, int band) const
std::string GeomMetadataSupplier::GetMetadataValue(std::string const& path, bool& hasValue, int band) const
{
auto value = this->m_MetadataDic.find(path);
if(value != this->m_MetadataDic.end())
......@@ -47,7 +48,7 @@ std::string GeomMetadataSupplier::GetMetadataValue(const std::string path, bool&
return "";
}
std::string GeomMetadataSupplier::GetResourceFile(std::string) const
std::string GeomMetadataSupplier::GetResourceFile(std::string const& s) const
{
return this->m_FileName;
}
......@@ -121,7 +122,7 @@ const boost::any& GeomMetadataSupplier::FetchRPC(ImageMetadata & imd)
return imd[MDGeom::RPC];
}
std::string GeomMetadataSupplier::PrintSelf()
std::string GeomMetadataSupplier::PrintSelf() const
{
std::ostringstream oss;
oss << "GeomMetadataSupplier: " << this->m_FileName << '\n';
......
......@@ -23,7 +23,7 @@
namespace otb
{
bool MetadataSupplierInterface::HasValue(const std::string path, int band)
bool MetadataSupplierInterface::HasValue(std::string const& path, int band)
{
bool hasValue;
const std::string ret = GetMetadataValue(path, hasValue, band);
......
......@@ -36,7 +36,7 @@ XMLMetadataSupplier::XMLMetadataSupplier(const std::string & fileName)
CPLDestroyXMLNode(psNode);
}
std::string XMLMetadataSupplier::GetMetadataValue(const std::string path, bool& hasValue, int band) const
std::string XMLMetadataSupplier::GetMetadataValue(std::string const& path, bool& hasValue, int band) const
{
const char * ret = CSLFetchNameValue(m_MetadataDic, path.c_str());
if (ret)
......@@ -49,7 +49,7 @@ std::string XMLMetadataSupplier::GetMetadataValue(const std::string path, bool&
return std::string(ret);
}
std::string XMLMetadataSupplier::GetFirstMetadataValue(const std::string path, bool& hasValue) const
std::string XMLMetadataSupplier::GetFirstMetadataValue(std::string const& path, bool& hasValue) const
{
// Search for the first joker
std::size_t found = path.find("_#");
......@@ -83,7 +83,7 @@ std::string XMLMetadataSupplier::GetFirstMetadataValue(const std::string path, b
}
}
std::string XMLMetadataSupplier::GetResourceFile(std::string) const
std::string XMLMetadataSupplier::GetResourceFile(std::string const& s) const
{
return m_FileName;
}
......
......@@ -206,11 +206,11 @@ public:
// MetadataSupplierInterface overrides
/** Get main image file */
std::string GetResourceFile(std::string="") const override;
std::string GetResourceFile(std::string const& s="") const override;
std::vector<std::string> GetResourceFiles() const override;
/** Get metadata item in GDALDataset, domain can specified as "domain/key" */
std::string GetMetadataValue(const std::string path, bool& hasValue, int band = -1) const override;
std::string GetMetadataValue(std::string const& path, bool& hasValue, int band = -1) const override;
/** Set metadata item in GDALDataset, domain can specified as prefix of the
* path, like "domain/key"*/
......
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