Skip to content

Commit

Permalink
Cleanup: strip our unused functions and clean up namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
gwaldron committed Apr 8, 2024
1 parent 0860070 commit 1d61057
Show file tree
Hide file tree
Showing 23 changed files with 791 additions and 1,202 deletions.
9 changes: 5 additions & 4 deletions src/rocky/Color.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <ctype.h>

using namespace ROCKY_NAMESPACE;
using namespace ROCKY_NAMESPACE::util;

namespace
{
Expand Down Expand Up @@ -160,7 +161,7 @@ Color::Color(const std::string& input, Format format)
{
std::string sub = t.substr(4, t.size() - 5);
util::StringTokenizer tok(",");
util::StringVector components;
std::vector<std::string> components;
tok.tokenize(sub, components);
if (components.size() == 3)
{
Expand All @@ -174,7 +175,7 @@ Color::Color(const std::string& input, Format format)
{
std::string sub = t.substr(5, t.size() - 6);
util::StringTokenizer tok(",");
util::StringVector components;
std::vector<std::string> components;
tok.tokenize(sub, components);
if (components.size() == 4)
{
Expand All @@ -189,7 +190,7 @@ Color::Color(const std::string& input, Format format)
{
std::string sub = t.substr(4, t.size() - 5);
util::StringTokenizer tok(",");
util::StringVector components;
std::vector<std::string> components;
tok.tokenize(sub, components);
if (components.size() == 3)
{
Expand Down Expand Up @@ -222,7 +223,7 @@ Color::Color(const std::string& input, Format format)
{
std::string sub = t.substr(5, t.size() - 6);
util::StringTokenizer tok(",");
util::StringVector components;
std::vector<std::string> components;
tok.tokenize(sub, components);
if (components.size() == 4)
{
Expand Down
2 changes: 0 additions & 2 deletions src/rocky/ElevationLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,6 @@ ElevationLayer::assembleHeightfield(const TileKey& key, const IOOptions& io) con
// If we actually got a Heightfield, resample/reproject it to match the incoming TileKey's extents.
if (geohf_list.size() > 0)
{
util::timer t;

unsigned width = 0;
unsigned height = 0;
auto keyExtent = key.extent();
Expand Down
1 change: 1 addition & 0 deletions src/rocky/Ellipsoid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "Math.h"

using namespace ROCKY_NAMESPACE;
using namespace ROCKY_NAMESPACE::util;

// https://en.wikipedia.org/wiki/World_Geodetic_System
#define WGS84_RADIUS_EQUATOR 6378137.0
Expand Down
1 change: 1 addition & 0 deletions src/rocky/Ephemeris.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "Ellipsoid.h"

using namespace ROCKY_NAMESPACE;
using namespace ROCKY_NAMESPACE::util;

namespace
{
Expand Down
1 change: 1 addition & 0 deletions src/rocky/GeoCircle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "Math.h"

using namespace ROCKY_NAMESPACE;
using namespace ROCKY_NAMESPACE::util;

#define LC "[GeoCircle] "

Expand Down
5 changes: 3 additions & 2 deletions src/rocky/GeoExtent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "Instance.h"

using namespace ROCKY_NAMESPACE;
using namespace ROCKY_NAMESPACE::util;

#undef LC
#define LC "[GeoExtent] "
Expand Down Expand Up @@ -905,7 +906,7 @@ GeoExtent::clamp()

if (_srs.isGeodetic())
{
_width = rocky::clamp(_width, 0.0, 360.0);
_width = rocky::util::clamp(_width, 0.0, 360.0);
//_height = osg::clampBetween(_height, 0.0, 180.0);

if (south() < -90.0)
Expand All @@ -918,7 +919,7 @@ GeoExtent::clamp()
_height -= (north()-90.0);
}

_height = rocky::clamp(_height, 0.0, 180.0);
_height = rocky::util::clamp(_height, 0.0, 180.0);
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/rocky/IOTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <rocky/Status.h>
#include <rocky/Units.h>
#include <rocky/Threading.h>
#include <rocky/LRUCache.h>

/**
* A collection of types used by the various I/O systems.
Expand Down Expand Up @@ -51,7 +52,7 @@ namespace ROCKY_NAMESPACE
std::string data;
};

using ContentCache = util::LRUCache<std::string, Result<Content>>;
using ContentCache = rocky::util::LRUCache<std::string, Result<Content>>;

class ROCKY_EXPORT Services
{
Expand Down
2 changes: 2 additions & 0 deletions src/rocky/Image.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

namespace ROCKY_NAMESPACE
{
using namespace ROCKY_NAMESPACE::util;

class IOOptions;

/**
Expand Down
1 change: 0 additions & 1 deletion src/rocky/ImageLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "ImageLayer.h"

#include "Color.h"
#include "ImageMosaic.h"
#include "IOTypes.h"
#include "Metrics.h"
#include "Utils.h"
Expand Down
113 changes: 0 additions & 113 deletions src/rocky/ImageMosaic.cpp

This file was deleted.

47 changes: 0 additions & 47 deletions src/rocky/ImageMosaic.h

This file was deleted.

74 changes: 74 additions & 0 deletions src/rocky/LRUCache.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/**
* rocky c++
* Copyright 2023 Pelican Mapping
* MIT License
*/
#pragma once
#include <rocky/Common.h>
#include <mutex>
#include <unordered_map>
#include <list>
#include <algorithm>

namespace ROCKY_NAMESPACE
{
namespace util
{
// Adapted from https://www.geeksforgeeks.org/lru-cache-implementation
template<class K, class V>
class LRUCache
{
private:
mutable std::mutex mutex;
int capacity;
using E = typename std::pair<K, V>;
typename std::list<E> cache;
std::unordered_map<K, typename std::list<E>::iterator> map;

public:
int hits = 0;
int gets = 0;

LRUCache(int capacity_ = 32) : capacity(capacity_) { }

inline void setCapacity(int value)
{
std::scoped_lock L(mutex);
cache.clear();
map.clear();
hits = 0;
gets = 0;
capacity = std::max(0, value);
}

inline V get(const K& key)
{
if (capacity == 0)
return V();
std::scoped_lock L(mutex);
++gets;
auto it = map.find(key);
if (it == map.end())
return V();
cache.splice(cache.end(), cache, it->second);
++hits;
return it->second->second;
}

inline void put(const K& key, const V& value)
{
if (capacity == 0)
return;
std::scoped_lock L(mutex);
if (cache.size() == capacity)
{
auto first_key = cache.front().first;
cache.pop_front();
map.erase(first_key);
}
cache.emplace_back(key, value);
map[key] = --cache.end();
}
};
}
}
Loading

0 comments on commit 1d61057

Please sign in to comment.