Skip to content

Commit

Permalink
Fixed illegal abstract in OperatorTest, #462: better static dependenc…
Browse files Browse the repository at this point in the history
…y management for TokenComponent
  • Loading branch information
MaartenHilferink committed Jul 5, 2024
1 parent f9ffeb4 commit 6d0e005
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 42 deletions.
13 changes: 11 additions & 2 deletions rtc/dll/src/RtcPCH.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// Copyright (C) 1998-2023 Object Vision b.v.
// Copyright (C) 1998-2024 Object Vision b.v.
// License: GNU GPL 3
/////////////////////////////////////////////////////////////////////////////

#if defined(_MSC_VER)
#pragma once
#endif

#if !defined(__RTC_PCH)
#define __RTC_PCH
Expand All @@ -15,6 +17,7 @@
#include "RtcBase.h"
#include "dbg/Check.h"
#include "dbg/debug.h"
#include "set/Token.h"

//----------------------------------------------------------------------
// RtcLock
Expand Down Expand Up @@ -50,6 +53,12 @@ struct RtcReportLock : RtcStreamLock, TokenComponent
~RtcReportLock();
};

struct StaticTokenID : TokenComponent, TokenID
{
StaticTokenID(CharPtr tokenStr) : TokenID(tokenStr, single_threading_tag_v) {}
StaticTokenID(CharPtr first, CharPtr last) : TokenID(first, last, single_threading_tag_v) {}
};

//----------------------------------------------------------------------
// Section : IString, used for returning string-handles to ClientAppl
//----------------------------------------------------------------------
Expand All @@ -63,9 +72,9 @@ struct IStringComponentLock : RtcStreamLock
};



#endif

//----------------------------------------------------------------------


#endif // __RTC_PCH
51 changes: 18 additions & 33 deletions rtc/dll/src/set/Token.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@ TokenComponent::TokenComponent()
{
if (!s_nrTokenComponents++)
{
dms_assert(!s_TokenListPtr);
assert(!s_TokenListPtr);
s_TokenListPtr.assign( new token_list_with_emptyzero );
}
dms_assert(s_TokenListPtr);
assert(s_TokenListPtr);
}

TokenComponent::~TokenComponent()
{
dms_assert(s_TokenListPtr);
dms_assert(s_nrTokenComponents);
assert(s_TokenListPtr);
assert(s_nrTokenComponents);

if (!--s_nrTokenComponents)
s_TokenListPtr.reset();
Expand Down Expand Up @@ -78,20 +78,6 @@ TokenID::TokenID(CharPtr tokenStr, mt_tag*)
dbg_assert(gd_TokenCreationBlockCount == 0 || s_TokenListPtr->size() == c);
}

TokenID::TokenID(CharPtr tokenStr, st_tag*, existing_tag*)
{
dms_assert(NoOtherThreadsStarted());
#if defined(MG_DEBUG)
SizeT c = s_TokenListPtr->size();
#endif
dms_assert(tokenStr);
m_ID = (tokenStr && *tokenStr) ? s_TokenListPtr->GetExisting_st(tokenStr) : 0;
if (!IsDefined(m_ID))
throwErrorF("TOKEN", "%s is not registered as token");
dms_assert(m_ID < s_TokenListPtr->size());
dbg_assert(s_TokenListPtr->size() == c);
}

TokenID::TokenID(CharPtr tokenStr, mt_tag*, existing_tag*)
{
#if defined(MG_DEBUG)
Expand Down Expand Up @@ -146,21 +132,6 @@ TokenID::TokenID(CharPtr first, CharPtr last, mt_tag*, existing_tag*)
dbg_assert(s_TokenListPtr->size() == c);
}

TokenID::TokenID(CharPtr first, CharPtr last, st_tag*, existing_tag*)
{
dms_assert(IsMainThread());
#if defined(MG_DEBUG)
SizeT c = s_TokenListPtr->size();
#endif
m_ID = (first != last)
? s_TokenListPtr->GetExisting_st(first, last)
: 0;
if (!IsDefined(m_ID))
throwErrorF("TOKEN", "%s is not registered as token");
dms_assert(m_ID < s_TokenListPtr->size());
dbg_assert(s_TokenListPtr->size() == c);
}

TokenID::TokenID(WeakStr str)
: m_ID(str.IsDefined() ? TokenID(str.begin(), str.send(), (mt_tag*)nullptr).m_ID : UNDEFINED_VALUE(UInt32) )
{}
Expand Down Expand Up @@ -267,3 +238,17 @@ RTC_CALL TokenID GetTrimmedTokenID(CharPtr first, CharPtr last)
Trim(range);
return GetTokenID_mt(range.first, range.second);
}


TokenID GetTokenID_st(CharPtr tokenStr)
{
static TokenComponent s_TokenService;
return TokenID(tokenStr, single_threading_tag_v);
}

TokenID GetTokenID_st(CharPtr first, CharPtr last)
{
static TokenComponent s_TokenService;
return TokenID(first, last, single_threading_tag_v);
}

12 changes: 7 additions & 5 deletions rtc/dll/src/set/Token.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,11 @@ struct TokenID
RTC_CALL explicit TokenID(CharPtr tokenStr, mt_tag*);
RTC_CALL explicit TokenID(CharPtr tokenStr, st_tag*);
RTC_CALL explicit TokenID(CharPtr tokenStr, mt_tag*, existing_tag*);
RTC_CALL explicit TokenID(CharPtr tokenStr, st_tag*, existing_tag*);
// RTC_CALL explicit TokenID(CharPtr tokenStr, st_tag*, existing_tag*);
RTC_CALL explicit TokenID(CharPtr first, CharPtr last, mt_tag*);
RTC_CALL explicit TokenID(CharPtr first, CharPtr last, st_tag*);
RTC_CALL explicit TokenID(CharPtr first, CharPtr last, mt_tag*, existing_tag*);
RTC_CALL explicit TokenID(CharPtr first, CharPtr last, st_tag*, existing_tag*);
// RTC_CALL explicit TokenID(CharPtr first, CharPtr last, st_tag*, existing_tag*);
RTC_CALL explicit TokenID(WeakStr str);
explicit TokenID(Undefined) : m_ID(UNDEFINED_VALUE(TokenT)) {}
// get id or -1 if not found
Expand Down Expand Up @@ -180,12 +180,14 @@ inline TokenID UndefinedValue(const TokenID*) { return TokenID(Undefined()); }
RTC_CALL void Trim(CharPtrRange& range);

// get or create id
inline TokenID GetTokenID_st(CharPtr tokenStr) { return TokenID(tokenStr, single_threading_tag_v); }
RTC_CALL TokenID GetTokenID_st(CharPtr tokenStr);
RTC_CALL TokenID GetTokenID_st(CharPtr first, CharPtr last);
inline TokenID GetTokenID_st(CharPtrRange range) { return GetTokenID_st(range.first, range.second); }


inline TokenID GetTokenID_mt(CharPtr tokenStr) { return TokenID(tokenStr, multi_threading_tag_v); }
inline TokenID GetTokenID_st(CharPtr first, CharPtr last) { return TokenID(first, last, single_threading_tag_v); }
inline TokenID GetTokenID_mt(CharPtr first, CharPtr last) { return TokenID(first, last, multi_threading_tag_v); }
RTC_CALL TokenID GetTrimmedTokenID(CharPtr first, CharPtr last);
inline TokenID GetTokenID_st(CharPtrRange range) { return GetTokenID_st(range.first, range.second); }
inline TokenID GetTokenID_mt(CharPtrRange range) { return GetTokenID_mt(range.first, range.second); }

template<typename TAG = mt_tag>
Expand Down
4 changes: 2 additions & 2 deletions stg/dll/src/GridStoragemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,8 @@ bool AbstrGridStorageManager::DoCheck50PercentExtentOverlap(StorageMetaInfoPtr s
return false;
}

auto read_area = Cardinality(curr_extent_in_world_coordinates);
auto intersection_area = Cardinality(intersect);
auto read_area = Area(curr_extent_in_world_coordinates);
auto intersection_area = Area(intersect);

auto intersection_faction = intersection_area / read_area;
if (intersection_faction < 0.5)
Expand Down

0 comments on commit 6d0e005

Please sign in to comment.