aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlloyd <[email protected]>2009-11-16 17:07:38 +0000
committerlloyd <[email protected]>2009-11-16 17:07:38 +0000
commit22a47e97f459337ff8c2b9fdcf68cb1514b19b34 (patch)
tree3eacf8d877eb0f3c6bc19f0b1995bedea224591c
parentfc5fadb281c509855a0ae20ecc70bfe9d681a1af (diff)
Use auto for long iterator names, etc.
It will be nice to convert to the range-based for loop once that's available.
-rw-r--r--src/algo_factory/algo_cache.h30
-rw-r--r--src/algo_factory/algo_factory.cpp3
-rw-r--r--src/alloc/mem_pool/mem_pool.cpp6
-rw-r--r--src/asn1/asn1_alt.cpp27
-rw-r--r--src/cert/x509/x509_ca.cpp6
-rw-r--r--src/cert/x509/x509cert.cpp16
-rw-r--r--src/cert/x509/x509stor.cpp3
-rw-r--r--src/libstate/libstate.cpp3
-rw-r--r--src/rng/hmac_rng/hmac_rng.cpp5
-rw-r--r--src/rng/randpool/randpool.cpp5
-rw-r--r--src/selftest/selftest.cpp3
-rw-r--r--src/utils/datastor/datastor.cpp7
-rw-r--r--src/utils/stl_util.h19
13 files changed, 43 insertions, 90 deletions
diff --git a/src/algo_factory/algo_cache.h b/src/algo_factory/algo_cache.h
index 4b264dcc1..09bbc4b5a 100644
--- a/src/algo_factory/algo_cache.h
+++ b/src/algo_factory/algo_cache.h
@@ -53,12 +53,8 @@ class Algorithm_Cache
~Algorithm_Cache();
private:
- typedef typename std::map<std::string, std::map<std::string, T*> >::iterator
- algorithms_iterator;
-
- typedef typename std::map<std::string, T*>::iterator provider_iterator;
-
- algorithms_iterator find_algorithm(const std::string& algo_spec);
+ typename std::map<std::string, std::map<std::string, T*> >::const_iterator
+ find_algorithm(const std::string& algo_spec);
std::mutex mutex;
std::map<std::string, std::string> aliases;
@@ -71,16 +67,15 @@ class Algorithm_Cache
* Assumes object lock is held
*/
template<typename T>
-typename Algorithm_Cache<T>::algorithms_iterator
+typename std::map<std::string, std::map<std::string, T*> >::const_iterator
Algorithm_Cache<T>::find_algorithm(const std::string& algo_spec)
{
- algorithms_iterator algo = algorithms.find(algo_spec);
+ auto algo = algorithms.find(algo_spec);
// Not found? Check if a known alias
if(algo == algorithms.end())
{
- std::map<std::string, std::string>::const_iterator alias =
- aliases.find(algo_spec);
+ auto alias = aliases.find(algo_spec);
if(alias != aliases.end())
algo = algorithms.find(alias->second);
@@ -98,14 +93,14 @@ const T* Algorithm_Cache<T>::get(const std::string& algo_spec,
{
std::lock_guard<std::mutex> lock(mutex);
- algorithms_iterator algo = find_algorithm(algo_spec);
+ auto algo = find_algorithm(algo_spec);
if(algo == algorithms.end()) // algo not found at all (no providers)
return 0;
// If a provider is requested specifically, return it or fail entirely
if(requested_provider != "")
{
- provider_iterator prov = algo->second.find(requested_provider);
+ auto prov = algo->second.find(requested_provider);
if(prov != algo->second.end())
return prov->second;
return 0;
@@ -117,7 +112,7 @@ const T* Algorithm_Cache<T>::get(const std::string& algo_spec,
const std::string pref_provider = search_map(pref_providers, algo_spec);
- for(provider_iterator i = algo->second.begin(); i != algo->second.end(); ++i)
+ for(auto i = algo->second.begin(); i != algo->second.end(); ++i)
{
const std::string prov_name = i->first;
const u32bit prov_weight = static_provider_weight(prov_name);
@@ -170,11 +165,10 @@ Algorithm_Cache<T>::providers_of(const std::string& algo_name)
std::vector<std::string> providers;
- algorithms_iterator algo = find_algorithm(algo_name);
-
+ auto algo = find_algorithm(algo_name);
if(algo != algorithms.end())
{
- provider_iterator provider = algo->second.begin();
+ auto provider = algo->second.begin();
while(provider != algo->second.end())
{
@@ -204,11 +198,11 @@ void Algorithm_Cache<T>::set_preferred_provider(const std::string& algo_spec,
template<typename T>
Algorithm_Cache<T>::~Algorithm_Cache()
{
- algorithms_iterator algo = algorithms.begin();
+ auto algo = algorithms.begin();
while(algo != algorithms.end())
{
- provider_iterator provider = algo->second.begin();
+ auto provider = algo->second.begin();
while(provider != algo->second.end())
{
diff --git a/src/algo_factory/algo_factory.cpp b/src/algo_factory/algo_factory.cpp
index 192d5ecdd..0b8422bcb 100644
--- a/src/algo_factory/algo_factory.cpp
+++ b/src/algo_factory/algo_factory.cpp
@@ -99,7 +99,8 @@ Algorithm_Factory::Algorithm_Factory(const std::vector<Engine*>& engines_in)
*/
Algorithm_Factory::~Algorithm_Factory()
{
- std::for_each(engines.begin(), engines.end(), del_fun<Engine>());
+ for(auto i = engines.begin(); i != engines.end(); ++i)
+ delete *i;
delete block_cipher_cache;
delete stream_cipher_cache;
diff --git a/src/alloc/mem_pool/mem_pool.cpp b/src/alloc/mem_pool/mem_pool.cpp
index 02a12d6a5..820355678 100644
--- a/src/alloc/mem_pool/mem_pool.cpp
+++ b/src/alloc/mem_pool/mem_pool.cpp
@@ -190,8 +190,8 @@ void Pooling_Allocator::deallocate(void* ptr, u32bit n)
{
const u32bit block_no = round_up(n, BLOCK_SIZE) / BLOCK_SIZE;
- std::vector<Memory_Block>::iterator i =
- std::lower_bound(blocks.begin(), blocks.end(), Memory_Block(ptr));
+ auto i = std::lower_bound(blocks.begin(), blocks.end(),
+ Memory_Block(ptr));
if(i == blocks.end() || !i->contains(ptr, block_no))
throw Invalid_State("Pointer released to the wrong allocator");
@@ -208,7 +208,7 @@ byte* Pooling_Allocator::allocate_blocks(u32bit n)
if(blocks.empty())
return 0;
- std::vector<Memory_Block>::iterator i = last_used;
+ auto i = last_used;
do
{
diff --git a/src/asn1/asn1_alt.cpp b/src/asn1/asn1_alt.cpp
index 41974eef6..401eb54e9 100644
--- a/src/asn1/asn1_alt.cpp
+++ b/src/asn1/asn1_alt.cpp
@@ -40,9 +40,8 @@ void AlternativeName::add_attribute(const std::string& type,
if(type == "" || str == "")
return;
- typedef std::multimap<std::string, std::string>::iterator iter;
- std::pair<iter, iter> range = alt_info.equal_range(type);
- for(iter j = range.first; j != range.second; ++j)
+ auto range = alt_info.equal_range(type);
+ for(auto j = range.first; j != range.second; ++j)
if(j->second == str)
return;
@@ -83,13 +82,11 @@ std::multimap<std::string, std::string> AlternativeName::contents() const
{
std::multimap<std::string, std::string> names;
- typedef std::multimap<std::string, std::string>::const_iterator rdn_iter;
- for(rdn_iter j = alt_info.begin(); j != alt_info.end(); ++j)
- multimap_insert(names, j->first, j->second);
+ for(auto i = alt_info.begin(); i != alt_info.end(); ++i)
+ multimap_insert(names, i->first, i->second);
- typedef std::multimap<OID, ASN1_String>::const_iterator on_iter;
- for(on_iter j = othernames.begin(); j != othernames.end(); ++j)
- multimap_insert(names, OIDS::lookup(j->first), j->second.value());
+ for(auto i = othernames.begin(); i != othernames.end(); ++i)
+ multimap_insert(names, OIDS::lookup(i->first), i->second.value());
return names;
}
@@ -111,19 +108,18 @@ void encode_entries(DER_Encoder& encoder,
const std::multimap<std::string, std::string>& attr,
const std::string& type, ASN1_Tag tagging)
{
- typedef std::multimap<std::string, std::string>::const_iterator iter;
+ auto range = attr.equal_range(type);
- std::pair<iter, iter> range = attr.equal_range(type);
- for(iter j = range.first; j != range.second; ++j)
+ for(auto i = range.first; i != range.second; ++i)
{
if(type == "RFC822" || type == "DNS" || type == "URI")
{
- ASN1_String asn1_string(j->second, IA5_STRING);
+ ASN1_String asn1_string(i->second, IA5_STRING);
encoder.add_object(tagging, CONTEXT_SPECIFIC, asn1_string.iso_8859());
}
else if(type == "IP")
{
- u32bit ip = string_to_ipv4(j->second);
+ u32bit ip = string_to_ipv4(i->second);
byte ip_buf[4] = { 0 };
store_be(ip, ip_buf);
encoder.add_object(tagging, CONTEXT_SPECIFIC, ip_buf, 4);
@@ -145,8 +141,7 @@ void AlternativeName::encode_into(DER_Encoder& der) const
encode_entries(der, alt_info, "URI", ASN1_Tag(6));
encode_entries(der, alt_info, "IP", ASN1_Tag(7));
- std::multimap<OID, ASN1_String>::const_iterator i;
- for(i = othernames.begin(); i != othernames.end(); ++i)
+ for(auto i = othernames.begin(); i != othernames.end(); ++i)
{
der.start_explicit(0)
.encode(i->first)
diff --git a/src/cert/x509/x509_ca.cpp b/src/cert/x509/x509_ca.cpp
index 3ba18e50e..6aba7e5a0 100644
--- a/src/cert/x509/x509_ca.cpp
+++ b/src/cert/x509/x509_ca.cpp
@@ -15,9 +15,6 @@
#include <botan/look_pk.h>
#include <botan/oids.h>
#include <botan/time.h>
-#include <algorithm>
-#include <typeinfo>
-#include <iterator>
#include <memory>
#include <set>
@@ -175,8 +172,7 @@ X509_CRL X509_CA::update_crl(const X509_CRL& crl,
for(u32bit j = 0; j != already_revoked.size(); ++j)
{
- std::set<SecureVector<byte> >::const_iterator i;
- i = removed_from_crl.find(already_revoked[j].serial_number());
+ auto i = removed_from_crl.find(already_revoked[j].serial_number());
if(i == removed_from_crl.end())
all_revoked.push_back(already_revoked[j]);
diff --git a/src/cert/x509/x509cert.cpp b/src/cert/x509/x509cert.cpp
index ac5839fb6..9be645dce 100644
--- a/src/cert/x509/x509cert.cpp
+++ b/src/cert/x509/x509cert.cpp
@@ -27,12 +27,8 @@ std::vector<std::string> lookup_oids(const std::vector<std::string>& in)
{
std::vector<std::string> out;
- std::vector<std::string>::const_iterator i = in.begin();
- while(i != in.end())
- {
+ for(auto i = in.begin(); i != in.end(); ++i)
out.push_back(OIDS::lookup(OID(*i)));
- ++i;
- }
return out;
}
@@ -320,9 +316,8 @@ X509_DN create_dn(const Data_Store& info)
X509_DN dn;
- std::multimap<std::string, std::string>::iterator j;
- for(j = names.begin(); j != names.end(); ++j)
- dn.add_attribute(j->first, j->second);
+ for(auto i = names.begin(); i != names.end(); ++i)
+ dn.add_attribute(i->first, i->second);
return dn;
}
@@ -356,9 +351,8 @@ AlternativeName create_alt_name(const Data_Store& info)
AlternativeName alt_name;
- std::multimap<std::string, std::string>::iterator j;
- for(j = names.begin(); j != names.end(); ++j)
- alt_name.add_attribute(j->first, j->second);
+ for(auto i = names.begin(); i != names.end(); ++i)
+ alt_name.add_attribute(i->first, i->second);
return alt_name;
}
diff --git a/src/cert/x509/x509stor.cpp b/src/cert/x509/x509stor.cpp
index 364bbac7b..323890f2d 100644
--- a/src/cert/x509/x509stor.cpp
+++ b/src/cert/x509/x509stor.cpp
@@ -603,8 +603,7 @@ X509_Code X509_Store::add_crl(const X509_CRL& crl)
revoked_info.serial = revoked_certs[j].serial_number();
revoked_info.auth_key_id = crl.authority_key_id();
- std::vector<CRL_Data>::iterator p =
- std::find(revoked.begin(), revoked.end(), revoked_info);
+ auto p = std::find(revoked.begin(), revoked.end(), revoked_info);
if(revoked_certs[j].reason_code() == REMOVE_FROM_CRL)
{
diff --git a/src/libstate/libstate.cpp b/src/libstate/libstate.cpp
index 80f694094..dd7fe7eaf 100644
--- a/src/libstate/libstate.cpp
+++ b/src/libstate/libstate.cpp
@@ -170,8 +170,7 @@ void Library_State::set(const std::string& section, const std::string& key,
std::string full_key = section + "/" + key;
- std::map<std::string, std::string>::const_iterator i =
- config.find(full_key);
+ auto i = config.find(full_key);
if(overwrite || i == config.end() || i->second == "")
config[full_key] = value;
diff --git a/src/rng/hmac_rng/hmac_rng.cpp b/src/rng/hmac_rng/hmac_rng.cpp
index 9d5ee97e4..213373657 100644
--- a/src/rng/hmac_rng/hmac_rng.cpp
+++ b/src/rng/hmac_rng/hmac_rng.cpp
@@ -8,7 +8,6 @@
#include <botan/hmac_rng.h>
#include <botan/loadstor.h>
#include <botan/xor_buf.h>
-#include <botan/stl_util.h>
#include <algorithm>
namespace Botan {
@@ -213,8 +212,8 @@ HMAC_RNG::~HMAC_RNG()
delete extractor;
delete prf;
- std::for_each(entropy_sources.begin(), entropy_sources.end(),
- del_fun<EntropySource>());
+ for(auto i = entropy_sources.begin(); i != entropy_sources.end(); ++i)
+ delete *i;
counter = 0;
}
diff --git a/src/rng/randpool/randpool.cpp b/src/rng/randpool/randpool.cpp
index af1706466..b04da7358 100644
--- a/src/rng/randpool/randpool.cpp
+++ b/src/rng/randpool/randpool.cpp
@@ -8,7 +8,6 @@
#include <botan/randpool.h>
#include <botan/loadstor.h>
#include <botan/xor_buf.h>
-#include <botan/stl_util.h>
#include <algorithm>
#include <chrono>
@@ -208,8 +207,8 @@ Randpool::~Randpool()
delete cipher;
delete mac;
- std::for_each(entropy_sources.begin(), entropy_sources.end(),
- del_fun<EntropySource>());
+ for(auto i = entropy_sources.begin(); i != entropy_sources.end(); ++i)
+ delete *i;
}
}
diff --git a/src/selftest/selftest.cpp b/src/selftest/selftest.cpp
index 660be36e4..d5b184f8f 100644
--- a/src/selftest/selftest.cpp
+++ b/src/selftest/selftest.cpp
@@ -114,8 +114,7 @@ namespace {
void verify_results(const std::string& algo,
const std::map<std::string, bool>& results)
{
- for(std::map<std::string, bool>::const_iterator i = results.begin();
- i != results.end(); ++i)
+ for(auto i = results.begin(); i != results.end(); ++i)
{
if(!i->second)
throw Self_Test_Failure(algo + " self-test failed, provider "+
diff --git a/src/utils/datastor/datastor.cpp b/src/utils/datastor/datastor.cpp
index 129dad9bf..9f8ba2c24 100644
--- a/src/utils/datastor/datastor.cpp
+++ b/src/utils/datastor/datastor.cpp
@@ -65,12 +65,9 @@ Data_Store::search_with(const Matcher& matcher) const
*/
std::vector<std::string> Data_Store::get(const std::string& looking_for) const
{
- typedef std::multimap<std::string, std::string>::const_iterator iter;
-
- std::pair<iter, iter> range = contents.equal_range(looking_for);
-
std::vector<std::string> out;
- for(iter i = range.first; i != range.second; ++i)
+ auto range = contents.equal_range(looking_for);
+ for(auto i = range.first; i != range.second; ++i)
out.push_back(i->second);
return out;
}
diff --git a/src/utils/stl_util.h b/src/utils/stl_util.h
index fc4d4effe..4cc081733 100644
--- a/src/utils/stl_util.h
+++ b/src/utils/stl_util.h
@@ -37,25 +37,6 @@ inline R search_map(const std::map<K, V>& mapping, const K& key,
}
/*
-* Function adaptor for delete operation
-*/
-template<class T>
-class del_fun : public std::unary_function<T, void>
- {
- public:
- void operator()(T* ptr) { delete ptr; }
- };
-
-/*
-* Delete the second half of a pair of objects
-*/
-template<typename Pair>
-void delete2nd(Pair& pair)
- {
- delete pair.second;
- }
-
-/*
* Insert a key/value pair into a multimap
*/
template<typename K, typename V>