mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-22 01:59:02 +00:00
Transform CoordCache::check/checkDim in ASSERT_DIM/POS macros
This makes it more obvious to the reader that these are actually assertions, and should help Coverity scan too.
This commit is contained in:
parent
3af0bad22a
commit
375aba7b5d
@ -11,9 +11,7 @@
|
||||
|
||||
#include "CoordCache.h"
|
||||
|
||||
|
||||
#include "support/debug.h"
|
||||
|
||||
#include "support/lassert.h"
|
||||
|
||||
|
||||
|
@ -11,9 +11,6 @@
|
||||
#ifndef COORDCACHE_H
|
||||
#define COORDCACHE_H
|
||||
|
||||
// It seems that MacOSX define the check macro.
|
||||
#undef check
|
||||
|
||||
#include "Dimension.h"
|
||||
|
||||
#include <unordered_map>
|
||||
@ -23,6 +20,24 @@ namespace lyx {
|
||||
class Inset;
|
||||
class MathData;
|
||||
|
||||
#ifdef ENABLE_ASSERTIONS
|
||||
#define ASSERT_HAS_DIM(thing, hint) \
|
||||
if (data_.find(thing) != data_.end()) \
|
||||
{} \
|
||||
else \
|
||||
lyxbreaker(thing, hint, data_.size());
|
||||
|
||||
#define ASSERT_HAS_POS(thing, hint) \
|
||||
auto it = data_.find(thing); \
|
||||
if (it != data_.end() && it->second.pos.x != -10000) \
|
||||
{} \
|
||||
else \
|
||||
lyxbreaker(thing, hint, data_.size());
|
||||
#else
|
||||
#define ASSERT_HAS_DIM(thing, hint)
|
||||
#define ASSERT_HAS_POS(thing, hint)
|
||||
#endif
|
||||
|
||||
void lyxbreaker(void const * data, const char * hint, int size);
|
||||
|
||||
struct Geometry {
|
||||
@ -94,37 +109,37 @@ public:
|
||||
|
||||
Geometry & geometry(T const * thing)
|
||||
{
|
||||
checkDim(thing, "geometry");
|
||||
ASSERT_HAS_DIM(thing, "geometry");
|
||||
return data_.find(thing)->second;
|
||||
}
|
||||
|
||||
Geometry const & geometry(T const * thing) const
|
||||
{
|
||||
checkDim(thing, "geometry");
|
||||
ASSERT_HAS_DIM(thing, "geometry");
|
||||
return data_.find(thing)->second;
|
||||
}
|
||||
|
||||
Dimension const & dim(T const * thing) const
|
||||
{
|
||||
checkDim(thing, "dim");
|
||||
ASSERT_HAS_DIM(thing, "dim");
|
||||
return data_.find(thing)->second.dim;
|
||||
}
|
||||
|
||||
int x(T const * thing) const
|
||||
{
|
||||
check(thing, "x");
|
||||
ASSERT_HAS_POS(thing, "x");
|
||||
return data_.find(thing)->second.pos.x;
|
||||
}
|
||||
|
||||
int y(T const * thing) const
|
||||
{
|
||||
check(thing, "y");
|
||||
ASSERT_HAS_POS(thing, "y");
|
||||
return data_.find(thing)->second.pos.y;
|
||||
}
|
||||
|
||||
Point xy(T const * thing) const
|
||||
{
|
||||
check(thing, "xy");
|
||||
ASSERT_HAS_POS(thing, "xy");
|
||||
return data_.find(thing)->second.pos;
|
||||
}
|
||||
|
||||
@ -159,24 +174,6 @@ public:
|
||||
private:
|
||||
friend class CoordCache;
|
||||
|
||||
#ifdef ENABLE_ASSERTIONS
|
||||
void checkDim(T const * thing, char const * hint) const
|
||||
{
|
||||
if (!hasDim(thing))
|
||||
lyxbreaker(thing, hint, data_.size());
|
||||
}
|
||||
|
||||
void check(T const * thing, char const * hint) const
|
||||
{
|
||||
if (!has(thing))
|
||||
lyxbreaker(thing, hint, data_.size());
|
||||
}
|
||||
#else
|
||||
void checkDim(T const *, char const * const ) const {}
|
||||
|
||||
void check(T const *, char const *) const {}
|
||||
#endif
|
||||
|
||||
typedef std::unordered_map<T const *, Geometry> cache_type;
|
||||
cache_type data_;
|
||||
};
|
||||
@ -213,12 +210,16 @@ public:
|
||||
/// Dump the contents of the cache to lyxerr in debugging form
|
||||
void dump() const;
|
||||
private:
|
||||
|
||||
/// MathDatas
|
||||
Arrays arrays_;
|
||||
// All insets
|
||||
Insets insets_;
|
||||
};
|
||||
|
||||
#undef ASSERT_HAS_DIM
|
||||
#undef ASSERT_HAS_POS
|
||||
|
||||
} // namespace lyx
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user