mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-20 13:23:59 +00:00
Organic Maps sources as of 02.04.2025 (fad26bbf22ac3da75e01e62aa01e5c8e11861005)
To expand with full Organic Maps and Maps.ME commits history run: git remote add om-historic [om-historic.git repo url] git fetch --tags om-historic git replace squashed-history historic-commits
This commit is contained in:
68
cppjansson/jansson_handle.hpp
Normal file
68
cppjansson/jansson_handle.hpp
Normal file
@@ -0,0 +1,68 @@
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
struct json_t;
|
||||
|
||||
namespace base
|
||||
{
|
||||
class JsonHandle
|
||||
{
|
||||
void IncRef();
|
||||
void DecRef();
|
||||
|
||||
public:
|
||||
JsonHandle(json_t * pJson = 0) : m_pJson(pJson)
|
||||
{
|
||||
IncRef();
|
||||
}
|
||||
|
||||
JsonHandle(JsonHandle const & json) : m_pJson(json.m_pJson)
|
||||
{
|
||||
IncRef();
|
||||
}
|
||||
|
||||
~JsonHandle()
|
||||
{
|
||||
DecRef();
|
||||
}
|
||||
|
||||
JsonHandle & operator = (JsonHandle const & json)
|
||||
{
|
||||
JsonHandle tmp(json);
|
||||
tmp.swap(*this);
|
||||
return *this;
|
||||
}
|
||||
|
||||
void swap(JsonHandle & json)
|
||||
{
|
||||
std::swap(m_pJson, json.m_pJson);
|
||||
}
|
||||
|
||||
json_t * get() const
|
||||
{
|
||||
return m_pJson;
|
||||
}
|
||||
|
||||
json_t * operator -> () const
|
||||
{
|
||||
return m_pJson;
|
||||
}
|
||||
|
||||
operator bool () const
|
||||
{
|
||||
return m_pJson != 0;
|
||||
}
|
||||
|
||||
/// Attach newly created object without incrementing ref count (it's already == 1).
|
||||
void AttachNew(json_t * pJson)
|
||||
{
|
||||
DecRef();
|
||||
|
||||
m_pJson = pJson;
|
||||
}
|
||||
|
||||
private:
|
||||
json_t * m_pJson;
|
||||
};
|
||||
} // namespace base
|
||||
Reference in New Issue
Block a user