Skip to content

Commit

Permalink
Adding const correctness where applicable
Browse files Browse the repository at this point in the history
  • Loading branch information
Graham Tremper committed Aug 14, 2014
1 parent 74122cc commit 7066f6f
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 47 deletions.
21 changes: 11 additions & 10 deletions autowiring/AutoPacket.h
Expand Up @@ -357,26 +357,27 @@ class AutoPacket:
/// </remarks>
template<class T, class... Ts>
void DecorateImmediate(const T& immed, const Ts&... immeds) {
// These are the things we're going to be working with while we perform immediate decoration:
static const std::type_info* sc_typeInfo [] = {&typeid(T), &typeid(Ts)...};
const void* pvImmeds [] = {&immed, &immeds...};
DecorationDisposition* pTypeSubs[1 + sizeof...(Ts)];

// None of the inputs may be shared pointers--if any of the inputs are shared pointers, they must be attached
// to this packet via Decorate, or else dereferenced and used that way.
static_assert(
!is_any<is_shared_ptr<T>, is_shared_ptr<Ts>...>::value,
"DecorateImmediate must not be used to attach a shared pointer, use Decorate on such a decoration instead"
);

// These are the things we're going to be working with while we perform immediate decoration:
static const std::type_info* s_argTypes [] = {&typeid(T), &typeid(Ts)...};
static const size_t s_arity = 1 + sizeof...(Ts);
const void* pvImmeds [] = {&immed, &immeds...};
DecorationDisposition* pTypeSubs[s_arity];

// Perform standard decoration with a short initialization:
{
std::lock_guard<std::mutex> lk(m_lock);
for(size_t i = 0; i <= sizeof...(Ts); i++) {
pTypeSubs[i] = &m_decorations[*sc_typeInfo[i]];
pTypeSubs[i] = &m_decorations[*s_argTypes[i]];
if(pTypeSubs[i]->wasCheckedOut) {
std::stringstream ss;
ss << "Cannot perform immediate decoration with type " << sc_typeInfo[i]->name()
ss << "Cannot perform immediate decoration with type " << s_argTypes[i]->name()
<< ", the requested decoration already exists";
throw std::runtime_error(ss.str());
}
Expand All @@ -392,16 +393,16 @@ class AutoPacket:
// Pulse satisfaction:
MakeAtExit([this, &pTypeSubs] {
// Mark entries as unsatisfiable:
for(auto pEntry : pTypeSubs) {
for(DecorationDisposition* pEntry : pTypeSubs) {
pEntry->satisfied = false;
pEntry->m_pImmediate = nullptr;
}

// Now trigger a rescan to hit any deferred, unsatisfiable entries:
for(const std::type_info* ti : {&typeid(T), &typeid(Ts)...})
for(const std::type_info* ti : s_argTypes)
MarkUnsatisfiable(*ti);
}),
PulseSatisfaction(pTypeSubs, 1 + sizeof...(Ts));
PulseSatisfaction(pTypeSubs, s_arity);
}

/// <summary>
Expand Down
8 changes: 4 additions & 4 deletions autowiring/Bolt.h
Expand Up @@ -19,11 +19,11 @@ class Bolt:
{
public:
const t_TypeInfoVector GetContextSigils(void) const override {
static const std::type_info* sc_types[] = {
static const std::type_info* s_types[] = {
&typeid(Sigil)...,
nullptr
};
return sc_types;
return s_types;
}

static_assert(!is_any_same<void, Sigil...>::value, "Can't use 'void' as a sigil type");
Expand All @@ -35,7 +35,7 @@ class Bolt<>:
{
public:
const t_TypeInfoVector GetContextSigils(void) const override {
static const std::type_info* sc_types[] = {nullptr};
return sc_types;
static const std::type_info* s_types[] = {nullptr};
return s_types;
}
};
6 changes: 3 additions & 3 deletions src/autonet/AutoNetServerImpl.cpp
Expand Up @@ -200,7 +200,7 @@ void AutoNetServerImpl::NewObject(CoreContext& ctxt, const AnySharedPointer& obj
// Check if type receives any events
{
Json::array listenerTypes;
for(auto& event : m_EventTypes) {
for(const auto& event : m_EventTypes) {
if(event->IsSameAs(objectPtr.get()))
listenerTypes.push_back(demangle(event->Type()));
}
Expand Down Expand Up @@ -240,15 +240,15 @@ void AutoNetServerImpl::HandleSubscribe(websocketpp::connection_hdl hdl) {
m_Subscribers.insert(hdl);

Json::array types;
for(auto type : m_AllTypes) {
for(const auto& type : m_AllTypes) {
types.push_back(type.first);
}

SendMessage(hdl, "subscribed", types);
AutoGlobalContext()->BuildCurrentState();

// Send breakpoint message
for(auto& breakpoint : m_breakpoints) {
for(const auto& breakpoint : m_breakpoints) {
SendMessage(hdl, "breakpoint", breakpoint);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/autotesting/AutowiringEnclosure.cpp
Expand Up @@ -49,8 +49,8 @@ void AutowiringEnclosure::OnTestEnd(const testing::TestInfo& info) {
assert(false);
}

static const char sc_autothrow[] = "AUTOTHROW_";
if(!strncmp(sc_autothrow, info.name(), ARRAYCOUNT(sc_autothrow) - 1))
static const char s_autothrow[] = "AUTOTHROW_";
if(!strncmp(s_autothrow, info.name(), ARRAYCOUNT(s_autothrow) - 1))
// Throw expected, end here
return;

Expand Down
10 changes: 5 additions & 5 deletions src/autowiring/AutoPacket.cpp
Expand Up @@ -87,7 +87,7 @@ void AutoPacket::MarkUnsatisfiable(const std::type_info& info) {

// Update satisfaction inside of lock
decoration = &dFind->second;
for(auto& satCounter : decoration->m_subscribers) {
for(const auto& satCounter : decoration->m_subscribers) {
if(satCounter.second)
// Entry is mandatory, leave it unsatisfaible
continue;
Expand Down Expand Up @@ -115,7 +115,7 @@ void AutoPacket::UpdateSatisfaction(const std::type_info& info) {

// Update satisfaction inside of lock
decoration = &dFind->second;
for(auto& satCounter : decoration->m_subscribers)
for(const auto& satCounter : decoration->m_subscribers)
if(satCounter.first->Decrement(satCounter.second))
callQueue.push_back(satCounter.first);
}
Expand Down Expand Up @@ -159,8 +159,8 @@ void AutoPacket::PulseSatisfaction(DecorationDisposition* pTypeSubs[], size_t nI
{
std::lock_guard<std::mutex> lk(m_lock);
for(size_t i = nInfos; i--;) {
for(auto& satCounter : pTypeSubs[i]->m_subscribers) {
auto& cur = satCounter.first;
for(const auto& satCounter : pTypeSubs[i]->m_subscribers) {
SatCounter* cur = satCounter.first;
if (satCounter.second) {
++cur->remaining;
}
Expand Down Expand Up @@ -194,7 +194,7 @@ void AutoPacket::Initialize(void) {

// Call all subscribers with no required or optional arguments:
// NOTE: This may result in decorations that cause other subscribers to be called.
for (auto* call : callCounters)
for (SatCounter* call : callCounters)
call->CallAutoFilter(*this);

// Initial satisfaction of the AutoPacket:
Expand Down
14 changes: 7 additions & 7 deletions src/autowiring/CoreContext.cpp
Expand Up @@ -65,7 +65,7 @@ CoreContext::~CoreContext(void) {
UnregisterEventReceiversUnsafe();

// Tell all context members that we're tearing down:
for(auto q : m_contextMembers)
for(ContextMember* q : m_contextMembers)
q->NotifyContextTeardown();
}

Expand Down Expand Up @@ -335,7 +335,7 @@ void CoreContext::Initiate(void) {
// Signal our condition variable
m_stateBlock->m_stateChanged.notify_all();

for(auto q : m_threads)
for(CoreRunnable* q : m_threads)
q->Start(outstanding);
}

Expand Down Expand Up @@ -470,7 +470,7 @@ void CoreContext::BuildCurrentState(void) {

// Recurse on all children
std::lock_guard<std::mutex> lk(m_stateBlock->m_lock);
for(auto c : m_children) {
for(const auto& c : m_children) {
auto cur = c.lock();
if(!cur)
continue;
Expand Down Expand Up @@ -538,8 +538,8 @@ void ShutdownCurrentContext(void) {

void CoreContext::UnregisterEventReceiversUnsafe(void) {
// Release all event receivers originating from this context:
for(auto q : m_eventReceivers)
m_junctionBoxManager->RemoveEventReceiver(q);
for(const auto& entry : m_eventReceivers)
m_junctionBoxManager->RemoveEventReceiver(entry);

// Notify our parent (if we have one) that our event receivers are going away:
if(m_pParent)
Expand Down Expand Up @@ -605,7 +605,7 @@ void CoreContext::UpdateDeferredElements(std::unique_lock<std::mutex>&& lk, cons
auto top = stk.top();
stk.pop();

for(auto* pNext = top; pNext; pNext = pNext->GetFlink()) {
for(DeferrableAutowiring* pNext = top; pNext; pNext = pNext->GetFlink()) {
pNext->SatisfyAutowiring(value.m_value->shared_ptr());

// See if there's another chain we need to process:
Expand Down Expand Up @@ -642,7 +642,7 @@ void CoreContext::UpdateDeferredElements(std::unique_lock<std::mutex>&& lk, cons
lk.unlock();

// Run through everything else and finalize it all:
for(auto cur : satisfiable)
for(const auto& cur : satisfiable)
cur.first->Finalize(cur.second);
}

Expand Down
13 changes: 6 additions & 7 deletions src/autowiring/test/ContextEnumeratorTest.cpp
Expand Up @@ -89,7 +89,7 @@ TEST_F(ContextEnumeratorTest, VerifyComplexEnumeration) {

// Verify there is only one context under the first context
int firstCount = 0;
for(auto ctxt : ContextEnumeratorT<NamedContext>(firstContext)) {
for(const auto& ctxt : ContextEnumeratorT<NamedContext>(firstContext)) {
firstCount++;
ASSERT_EQ(ctxt, firstNamed);
ASSERT_EQ(ctxt->GetParentContext(), firstContext);
Expand All @@ -98,18 +98,17 @@ TEST_F(ContextEnumeratorTest, VerifyComplexEnumeration) {

// Verify there is only one context under the second context
int secondCount = 0;
for(auto ctxt : ContextEnumeratorT<NamedContext>(secondContext)) {
for(const auto& ctxt : ContextEnumeratorT<NamedContext>(secondContext)) {
secondCount++;
ASSERT_EQ(ctxt, secondNamed);
ASSERT_EQ(ctxt->GetParentContext(), secondContext);
}
ASSERT_EQ(secondCount, 1) << "Expected exactly one context in the parent context, found " << secondCount;

// Verify global context structure
int globalCount = 0;
for(auto ctxt : ContextEnumeratorT<NamedContext>(AutoGlobalContext())) {
globalCount++;
}
auto enumerator = ContextEnumeratorT<NamedContext>(AutoGlobalContext());
int globalCount = std::distance(enumerator.begin(), enumerator.end());

ASSERT_EQ(globalCount, 2) << "Expected exactly one context in the parent context, found " << globalCount;
}

Expand Down Expand Up @@ -168,7 +167,7 @@ TEST_F(ContextEnumeratorTest, ComplexRemovalInterference) {
}

// Now verify that nothing we eliminated was enumerated:
for(auto& cur : eliminated)
for(const auto& cur : eliminated)
ASSERT_TRUE(cur.expired()) << "Found an element that was iterated after it should have been unreachable";
}

4 changes: 2 additions & 2 deletions src/autowiring/test/CoreContextTest.cpp
Expand Up @@ -24,7 +24,7 @@ TEST_F(CoreContextTest, TestEnumerateChildren) {

// Enumerate and see what we get back:
std::set<std::shared_ptr<CoreContext>> allChildren;
for(auto cur : CurrentContextEnumerator())
for(const auto& cur : CurrentContextEnumerator())
allChildren.insert(cur);

// Verify we get exactly four back:
Expand Down Expand Up @@ -70,7 +70,7 @@ TEST_F(CoreContextTest, TestEarlyLambdaReturn) {
// Enumerate, but stop after three:
std::vector<std::shared_ptr<CoreContext>> allChildren;
size_t totalSoFar = 0;
for(auto& ctxt : CurrentContextEnumerator()) {
for(const auto& ctxt : CurrentContextEnumerator()) {
if(totalSoFar++ == 3)
break;
allChildren.push_back(ctxt);
Expand Down
6 changes: 3 additions & 3 deletions src/autowiring/test/EventReceiverTest.cpp
Expand Up @@ -99,11 +99,11 @@ TEST_F(EventReceiverTest, NontrivialCopy) {
// Accept dispatch delivery:
//receiver->AcceptDispatchDelivery();

static const int sc_numElems = 10;
static const int s_numElems = 10;

// Create the vector we're going to copy over:
vector<int> ascending;
for(int i = 0; i < sc_numElems; i++)
for(int i = 0; i < s_numElems; i++)
ascending.push_back(i);

// Deferred fire:
Expand All @@ -122,7 +122,7 @@ TEST_F(EventReceiverTest, NontrivialCopy) {

// Validate our vectors:
ASSERT_EQ(10, (int)receiver->m_myVec.size()) << "Receiver was not populated correctly with a vector";
for(int i = 0; i < sc_numElems; i++)
for(int i = 0; i < s_numElems; i++)
EXPECT_EQ(i, ascending[i]) << "Element at offset " << i << " was incorrectly copied";
}

Expand Down
6 changes: 3 additions & 3 deletions src/autowiring/test/ObjectPoolTest.cpp
Expand Up @@ -270,13 +270,13 @@ TEST_F(ObjectPoolTest, MovableObjectPool) {
}

TEST_F(ObjectPoolTest, MovableObjectPoolAysnc) {
static const size_t sc_count = 10000;
static const size_t s_count = 10000;
ObjectPool<int> from;

{
// Issue a zillion objects from the from pool:
std::vector<std::shared_ptr<int>> objs;
for(size_t i = sc_count; i--;)
for(size_t i = s_count; i--;)
objs.push_back(from.Wait());

// Make a thread, let it hold these objects while we move its pool:
Expand All @@ -291,5 +291,5 @@ TEST_F(ObjectPoolTest, MovableObjectPoolAysnc) {
AutoCurrentContext()->SignalShutdown(true);

// Verify that new pool got all of the objects:
ASSERT_EQ(sc_count, to.GetCached()) << "Object pool move operation did not correctly relay checked out types";
ASSERT_EQ(s_count, to.GetCached()) << "Object pool move operation did not correctly relay checked out types";
}
2 changes: 1 addition & 1 deletion src/autowiring/test/PostConstructTest.cpp
Expand Up @@ -17,7 +17,7 @@ class ContextExposer:
public:
size_t DeferredCount(void) const {
size_t ct = 0;
for(auto& entry : CoreContext::m_typeMemos)
for(const auto& entry : CoreContext::m_typeMemos)
for(auto cur = entry.second.pFirst; cur; cur = cur->GetFlink())
ct++;
return ct;
Expand Down

0 comments on commit 7066f6f

Please sign in to comment.