Skip to content

Commit 758310e

Browse files
committed
workaround for not calling virtual method from constructor
1 parent 95bab10 commit 758310e

File tree

3 files changed

+10
-30
lines changed

3 files changed

+10
-30
lines changed

src/lib_modules/core/output.hpp

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -75,18 +75,21 @@ class IOutputCap {
7575
protected:
7676
template <typename InstanceType, typename ...Args>
7777
InstanceType* addOutput(Args&&... args) {
78-
auto p = createOutput<InstanceType>(getAllocatorSize(), std::forward<Args>(args)...);
79-
addOutputInternal(p);
78+
auto p = createOutput<InstanceType>(allocatorSize, std::forward<Args>(args)...);
79+
outputs.push_back(uptr(p));
8080
return safe_cast<InstanceType>(p);
8181
}
8282

83-
virtual size_t getAllocatorSize() const = 0;
84-
virtual void addOutputInternal(IOutput *p) = 0;
83+
/*FIXME: we need to have factories to move these back to the implementation - otherwise pins created from the constructor may crash*/
84+
std::vector<std::unique_ptr<IOutput>> outputs;
85+
/*const*/ size_t allocatorSize;
8586
};
8687

8788
class OutputCap : public virtual IOutputCap {
8889
public:
89-
OutputCap(size_t allocatorSize) : allocatorSize(allocatorSize) {}
90+
OutputCap(size_t allocatorSize) {
91+
this->allocatorSize = allocatorSize;
92+
}
9093
virtual ~OutputCap() noexcept(false) {}
9194

9295
virtual size_t getNumOutputs() const override {
@@ -95,19 +98,6 @@ class OutputCap : public virtual IOutputCap {
9598
virtual IOutput* getOutput(size_t i) const override {
9699
return outputs[i].get();
97100
}
98-
99-
protected:
100-
virtual size_t getAllocatorSize() const override {
101-
assert(allocatorSize > 0);
102-
return allocatorSize;
103-
}
104-
virtual void addOutputInternal(IOutput *p) override {
105-
outputs.push_back(uptr(p));
106-
}
107-
108-
private:
109-
std::vector<std::unique_ptr<IOutput>> outputs;
110-
const size_t allocatorSize;
111101
};
112102

113103
}

src/lib_modules/utils/helper.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace Modules {
1010

1111
/* this default factory creates output pins with the default output - create another one for other uses such as low latency */
1212
template <typename InstanceType>
13-
struct ModuleDefault : public virtual OutputCap, public virtual InstanceType {
13+
struct ModuleDefault : public OutputCap, public InstanceType {
1414
template <typename ...Args>
1515
ModuleDefault(size_t allocatorSize, Args&&... args) : OutputCap(allocatorSize), InstanceType(std::forward<Args>(args)...) {}
1616
};

src/lib_modules/utils/pipeline.cpp

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,8 @@ class PipelinedInput : public IInput {
5353
IProcessExecutor &executor;
5454
};
5555

56-
/* Fake: requested by IOuputCap */
57-
struct OutputCapFake : public virtual IOutputCap {
58-
virtual size_t getAllocatorSize() const override final {
59-
throw Exception("getAllocatorSize() not implemented for Pipeline");
60-
}
61-
virtual void addOutputInternal(IOutput *p) override final {
62-
throw Exception("addOutputInternal() not implemented for Pipeline");
63-
}
64-
};
65-
6656
/* Wrapper around the module. */
67-
class PipelinedModule : public ICompletionNotifier, public IPipelinedModule, public InputCap, public OutputCapFake {
57+
class PipelinedModule : public ICompletionNotifier, public IPipelinedModule, public InputCap {
6858
public:
6959
/* take ownership of module */
7060
PipelinedModule(IModule *module, ICompletionNotifier *notify)

0 commit comments

Comments
 (0)