Mercurial > hg > orthanc
changeset 6777:26849c442955
publishing SharedObjectCache::ISizeProvider as IObjectSizeProvider
| author | Sebastien Jodogne <s.jodogne@gmail.com> |
|---|---|
| date | Tue, 12 May 2026 18:20:35 +0200 |
| parents | a5d1aa442f75 |
| children | faf21787ac71 |
| files | OrthancFramework/Sources/Cache/IObjectSizeProvider.h OrthancFramework/Sources/Cache/SharedObjectCache.cpp OrthancFramework/Sources/Cache/SharedObjectCache.h OrthancFramework/Sources/MultiThreading/Mutex.h |
| diffstat | 4 files changed, 54 insertions(+), 30 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/OrthancFramework/Sources/Cache/IObjectSizeProvider.h Tue May 12 18:20:35 2026 +0200 @@ -0,0 +1,41 @@ +/** + * Orthanc - A Lightweight, RESTful DICOM Store + * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics + * Department, University Hospital of Liege, Belgium + * Copyright (C) 2017-2023 Osimis S.A., Belgium + * Copyright (C) 2024-2026 Orthanc Team SRL, Belgium + * Copyright (C) 2021-2026 Sebastien Jodogne, ICTEAM UCLouvain, Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/>. + **/ + + +#pragma once + +#include "../IDynamicObject.h" + + +namespace Orthanc +{ + class ORTHANC_PUBLIC IObjectSizeProvider : public boost::noncopyable + { + public: + virtual ~IObjectSizeProvider() + { + } + + virtual size_t GetSize(const IDynamicObject& object) const = 0; + }; +}
--- a/OrthancFramework/Sources/Cache/SharedObjectCache.cpp Tue May 12 18:12:22 2026 +0200 +++ b/OrthancFramework/Sources/Cache/SharedObjectCache.cpp Tue May 12 18:20:35 2026 +0200 @@ -81,7 +81,7 @@ } - SharedObjectCache::SharedObjectCache(ISizeProvider* provider, + SharedObjectCache::SharedObjectCache(IObjectSizeProvider* provider, size_t capacity) : provider_(provider), capacity_(capacity),
--- a/OrthancFramework/Sources/Cache/SharedObjectCache.h Tue May 12 18:12:22 2026 +0200 +++ b/OrthancFramework/Sources/Cache/SharedObjectCache.h Tue May 12 18:20:35 2026 +0200 @@ -24,9 +24,8 @@ #pragma once -#include "../Compatibility.h" -#include "../IDynamicObject.h" #include "../MultiThreading/Mutex.h" +#include "IObjectSizeProvider.h" #include "LeastRecentlyUsedIndex.h" #include <boost/shared_ptr.hpp> @@ -36,42 +35,22 @@ { class ORTHANC_PUBLIC SharedObjectCache : public boost::noncopyable { - public: - class ORTHANC_PUBLIC ISizeProvider : public boost::noncopyable - { - public: - virtual ~ISizeProvider() - { - } - - virtual size_t GetSize(const IDynamicObject& object) const = 0; - }; - - class StringSizeProvider : public ISizeProvider - { - public: - virtual size_t GetSize(const IDynamicObject& object) const ORTHANC_OVERRIDE - { - return dynamic_cast<const SingleValueObject<std::string>&>(object).GetValue().size(); - } - }; - private: class Item; typedef std::map<std::string, Item*> Content; - Mutex mutex_; - std::unique_ptr<ISizeProvider> provider_; - LeastRecentlyUsedIndex<std::string> lru_; - Content content_; - size_t capacity_; - size_t currentSize_; + Mutex mutex_; + std::unique_ptr<IObjectSizeProvider> provider_; + LeastRecentlyUsedIndex<std::string> lru_; + Content content_; + size_t capacity_; + size_t currentSize_; void MakeRoom(size_t newObjectSize); public: - SharedObjectCache(ISizeProvider* provider /* takes ownership */, + SharedObjectCache(IObjectSizeProvider* provider /* takes ownership */, size_t capacity); ~SharedObjectCache();
--- a/OrthancFramework/Sources/MultiThreading/Mutex.h Tue May 12 18:12:22 2026 +0200 +++ b/OrthancFramework/Sources/MultiThreading/Mutex.h Tue May 12 18:20:35 2026 +0200 @@ -24,6 +24,10 @@ #pragma once +#include "../OrthancFramework.h" + +#include <boost/noncopyable.hpp> + #if !defined(__EMSCRIPTEN__) # include <boost/thread/mutex.hpp> #endif
