Skip to content

Commit c4b30fa

Browse files
committed
Separated factory from producible; Bumped Anyness
1 parent 6da2f1a commit c4b30fa

8 files changed

Lines changed: 137 additions & 109 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ if (PROJECT_IS_TOP_LEVEL OR NOT LANGULUS)
1010
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
1111
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
1212
include(LangulusUtilities.cmake)
13-
fetch_langulus_module(Anyness GIT_TAG 695bab64069f99e3dd0a53b069741c99c52e2895)
13+
fetch_langulus_module(Anyness GIT_TAG fa338f47e8274e3222141f0457e342ea63b331ba)
1414
endif()
1515

1616
file(GLOB_RECURSE
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
///
2+
/// Langulus::Flow
3+
/// Copyright (c) 2017 Dimo Markov <team@langulus.com>
4+
/// Part of the Langulus framework, see https://langulus.com
5+
///
6+
/// SPDX-License-Identifier: GPL-3.0-or-later
7+
///
8+
#pragma once
9+
#include "../../../source/Producible.inl"

source/Common.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,11 @@ namespace Langulus::Flow
5656
return (static_cast<int>(lhs) & static_cast<int>(rhs)) != 0;
5757
}
5858

59+
/// Usage styles for TFactory
60+
enum class FactoryUsage {
61+
Default, // Default factories aggregate duplicated items
62+
Unique // Unique factories never duplicate items (a set)
63+
};
64+
5965
} // namespace Langulus::Flow
6066

source/Producible.hpp

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
///
2+
/// Langulus::Flow
3+
/// Copyright (c) 2017 Dimo Markov <team@langulus.com>
4+
/// Part of the Langulus framework, see https://langulus.com
5+
///
6+
/// SPDX-License-Identifier: GPL-3.0-or-later
7+
///
8+
#pragma once
9+
#include "Common.hpp"
10+
#include <Langulus/Anyness/Many.hpp>
11+
#include <Langulus/Anyness/Ref.hpp>
12+
13+
14+
namespace Langulus::Flow
15+
{
16+
17+
///
18+
/// An element, that is factory produced (used as CRTP)
19+
///
20+
/// Saves the descriptor by which the item was made with, in order to
21+
/// compare creation requests
22+
/// @attention mDescriptor can contain anything (including Thing
23+
/// references) and is known to cause circular dependencies. That's
24+
/// why ProducedFrom::Teardown has to be called as a first-stage
25+
/// destruction, usually in a custom Reference(int) routine.
26+
///
27+
template<class T>
28+
class ProducedFrom {
29+
LANGULUS(PRODUCER) T;
30+
31+
protected:
32+
template<class, FactoryUsage>
33+
friend class TFactory;
34+
35+
// The descriptor used for hashing and element identification
36+
Many mDescriptor;
37+
// The producer of the element
38+
Ref<T> mProducer;
39+
40+
public:
41+
ProducedFrom(const ProducedFrom&) = delete;
42+
ProducedFrom(ProducedFrom&&);
43+
ProducedFrom(T* = nullptr, const Many& = {});
44+
45+
template<template<class> class S>
46+
ProducedFrom(S<ProducedFrom>&&) requires CT::Intent<S<ProducedFrom>>;
47+
48+
auto GetDescriptor() const noexcept -> const Many&;
49+
Hash GetHash() const noexcept;
50+
auto GetProducer() const noexcept -> const Ref<T>&;
51+
void TeardownInner();
52+
};
53+
54+
} // namespace Langulus::Flow

source/Producible.inl

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
///
2+
/// Langulus::Flow
3+
/// Copyright (c) 2017 Dimo Markov <team@langulus.com>
4+
/// Part of the Langulus framework, see https://langulus.com
5+
///
6+
/// SPDX-License-Identifier: GPL-3.0-or-later
7+
///
8+
#pragma once
9+
#include "Producible.hpp"
10+
11+
12+
namespace Langulus::Flow
13+
{
14+
15+
/// Move a produced item
16+
/// @param other - the item to move
17+
template<class T> LANGULUS(INLINED)
18+
ProducedFrom<T>::ProducedFrom(ProducedFrom&& other)
19+
: ProducedFrom {Move(other)} {}
20+
21+
/// Generic construction
22+
/// @param other - intent and element to initialize with
23+
template<class T> template<template<class> class S> LANGULUS(INLINED)
24+
ProducedFrom<T>::ProducedFrom(S<ProducedFrom>&& other)
25+
requires CT::Intent<S<ProducedFrom>>
26+
// mProducer intentionally not overwritten
27+
: mDescriptor {other.Nest(other->mDescriptor)} {}
28+
29+
/// Construct a produced item
30+
/// @param producer - the item's producer
31+
/// @param descriptor - the item's neat descriptor
32+
template<class T> LANGULUS(INLINED)
33+
ProducedFrom<T>::ProducedFrom(T* producer, const Many& descriptor)
34+
: mDescriptor {descriptor}
35+
, mProducer {producer} {}
36+
37+
/// Get the normalized descriptor of the produced item
38+
/// @return the normalized descriptor
39+
template<class T> LANGULUS(INLINED)
40+
auto ProducedFrom<T>::GetDescriptor() const noexcept -> const Many& {
41+
return mDescriptor;
42+
}
43+
44+
/// Get the hash of the normalized descriptor (cached and efficient)
45+
/// @return the hash
46+
template<class T> LANGULUS(INLINED)
47+
Hash ProducedFrom<T>::GetHash() const noexcept {
48+
return mDescriptor.GetHash();
49+
}
50+
51+
/// Return the producer of the item (a.k.a. the owner of the factory)
52+
/// @return a pointer to the producer instance
53+
template<class T> LANGULUS(INLINED)
54+
auto ProducedFrom<T>::GetProducer() const noexcept -> const Ref<T>& {
55+
return mProducer;
56+
}
57+
58+
/// Return the producer of the item (a.k.a. the owner of the factory)
59+
/// @return a pointer to the producer instance
60+
template<class T> LANGULUS(INLINED)
61+
void ProducedFrom<T>::TeardownInner() {
62+
mDescriptor.Reset();
63+
mProducer.Reset();
64+
}
65+
66+
} // namespace Langulus::Flow

source/TFactory.hpp

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,12 @@
77
///
88
#pragma once
99
#include "Common.hpp"
10-
//#include <Langulus/Anyness/Neat.hpp>
1110
#include <Langulus/Anyness/THive.hpp>
1211

1312

1413
namespace Langulus::Flow
1514
{
1615

17-
/// Usage styles for TFactory
18-
enum class FactoryUsage {
19-
Default, // Default factories aggregate duplicated items
20-
Unique // Unique factories never duplicate items (a set)
21-
};
22-
23-
/// Concept for determining if a type is producible from a factory
24-
/// The type must have a producer defined, not be abstract, be dense, and
25-
/// be referencable
26-
template<class...T>
27-
concept FactoryProducible = ((CT::Producible<T>
28-
and not CT::Abstract<T> and CT::Dense<T> and CT::Referencable<T>)
29-
and ...);
30-
31-
3216
///
3317
/// Factory container
3418
///
@@ -94,42 +78,4 @@ namespace Langulus::Flow
9478
template<class T>
9579
using TFactoryUnique = TFactory<T, FactoryUsage::Unique>;
9680

97-
98-
///
99-
/// An element, that is factory produced (used as CRTP)
100-
///
101-
/// Saves the descriptor by which the item was made with, in order to
102-
/// compare creation requests
103-
/// @attention mDescriptor can contain anything (including Thing
104-
/// references) and is known to cause circular dependencies. That's
105-
/// why ProducedFrom::Teardown has to be called as a first-stage
106-
/// destruction, usually in a custom Reference(int) routine.
107-
///
108-
template<class T>
109-
class ProducedFrom {
110-
LANGULUS(PRODUCER) T;
111-
112-
protected:
113-
template<class, FactoryUsage>
114-
friend class TFactory;
115-
116-
// The descriptor used for hashing and element identification
117-
Many mDescriptor;
118-
// The producer of the element
119-
Ref<T> mProducer;
120-
121-
public:
122-
ProducedFrom(const ProducedFrom&) = delete;
123-
ProducedFrom(ProducedFrom&&);
124-
ProducedFrom(T* = nullptr, const Many& = {});
125-
126-
template<template<class> class S>
127-
ProducedFrom(S<ProducedFrom>&&) requires CT::Intent<S<ProducedFrom>>;
128-
129-
auto GetDescriptor() const noexcept -> const Many&;
130-
Hash GetHash() const noexcept;
131-
auto GetProducer() const noexcept -> const Ref<T>&;
132-
void TeardownInner();
133-
};
134-
13581
} // namespace Langulus::Flow

source/TFactory.inl

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -330,60 +330,6 @@ namespace Langulus::Flow
330330
Base::Destroy(item);
331331
}
332332

333-
334-
335-
336-
/// Move a produced item
337-
/// @param other - the item to move
338-
template<class T> LANGULUS(INLINED)
339-
ProducedFrom<T>::ProducedFrom(ProducedFrom&& other)
340-
: ProducedFrom {Move(other)} {}
341-
342-
/// Generic construction
343-
/// @param other - intent and element to initialize with
344-
template<class T> template<template<class> class S> LANGULUS(INLINED)
345-
ProducedFrom<T>::ProducedFrom(S<ProducedFrom>&& other)
346-
requires CT::Intent<S<ProducedFrom>>
347-
// mProducer intentionally not overwritten
348-
: mDescriptor {other.Nest(other->mDescriptor)} {}
349-
350-
/// Construct a produced item
351-
/// @param producer - the item's producer
352-
/// @param descriptor - the item's neat descriptor
353-
template<class T> LANGULUS(INLINED)
354-
ProducedFrom<T>::ProducedFrom(T* producer, const Many& descriptor)
355-
: mDescriptor {descriptor}
356-
, mProducer {producer} {}
357-
358-
/// Get the normalized descriptor of the produced item
359-
/// @return the normalized descriptor
360-
template<class T> LANGULUS(INLINED)
361-
auto ProducedFrom<T>::GetDescriptor() const noexcept -> const Many& {
362-
return mDescriptor;
363-
}
364-
365-
/// Get the hash of the normalized descriptor (cached and efficient)
366-
/// @return the hash
367-
template<class T> LANGULUS(INLINED)
368-
Hash ProducedFrom<T>::GetHash() const noexcept {
369-
return mDescriptor.GetHash();
370-
}
371-
372-
/// Return the producer of the item (a.k.a. the owner of the factory)
373-
/// @return a pointer to the producer instance
374-
template<class T> LANGULUS(INLINED)
375-
auto ProducedFrom<T>::GetProducer() const noexcept -> const Ref<T>& {
376-
return mProducer;
377-
}
378-
379-
/// Return the producer of the item (a.k.a. the owner of the factory)
380-
/// @return a pointer to the producer instance
381-
template<class T> LANGULUS(INLINED)
382-
void ProducedFrom<T>::TeardownInner() {
383-
mDescriptor.Reset();
384-
mProducer.Reset();
385-
}
386-
387333
} // namespace Langulus::Flow
388334

389335
#undef TEMPLATE

test/Common.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
/// Include this file once in each cpp file, after all other headers
1111
#include <Langulus/Flow/Resolvable.hpp>
1212
#include <Langulus/Flow/Factory.hpp>
13+
#include <Langulus/Flow/Producible.hpp>
1314
#include <Langulus/Testing.hpp>
1415

1516
using namespace Flow;

0 commit comments

Comments
 (0)