betterc-interface 1.0.1
Interfaces and Dynamic Casts for betterC classes.
To use this package, run the following command in your project's root directory:
Manual usage
Put the following dependency into your project's dependences section:
betterc-interfaces
Provides interface compatibility to D -betterC flag. Poymorphism and dynamic casts on betterC!
What it can do
- Implement multiple interfaces
- Dynamic casts
- Inheritance
Limitations
- Can't define a new destructor
- Usage of
interfaces
is done viaabstract class
instead of interface itself. This happens because simply by usinginterface
keyword, D refuses to build. opCast
can't be defined as of now, usegetInterface!T
. This happens because opCast breaksemplace
, so, you won't be able to allocate a new class.- If your constructor has parameters, you won't be able extend that class with
CppExtend
it (unless you do a default params constructor) - Needs to call getInterface! for functions accepting super class when using
CppExtend
:
interface IInterfaceA {}
interface IInterfaceB {}
class Test : CppInterface!(Test, IInterfaceA){}
class Test2 : CppExtend!(Test2, Test, IInterfaceB){}
void test(Test t){}
Test2 t = New!Test2();
test(t); //Fails
//Instead, use:
test(t.getInterface!Test);
Example Usage:
extern(C++)
{
///Interface
abstract class Printable
{
void print();
}
///Interface
abstract class Stringificable
{
extern(D) string toString2();
}
///New class implementing Printable and Stringificable classes
class Test : CppInterface!(Test, Printable, Stringificable)
{
void print()
{
import core.stdc.stdio;
printf("toString on print function: %s\n", toString2.ptr);
}
extern(D) string toString2()
{
return __traits(identifier, Test);
}
}
abstract class DoIt
{
void doIt();
}
///Extend and include new interface
class Test2 : CppExtend!(Test2, Test, DoIt)
{
void doIt()
{
import core.stdc.stdio;
printf("Done it!\n");
}
}
///Simply extend existing class with interface
class Test3 : Test
{
}
}
extern(C) void main()
{
Test2 t = New!Test2();
t.print;
t.doIt();
}
- 1.0.1 released a year ago
- MrcSnm/betterc-interfaces
- BSL-1.0
- Copyright © 2023, Hipreme
- Authors:
- Dependencies:
- none
- Versions:
-
1.0.1 2023-Jan-02 1.0.0 2023-Jan-02 ~master 2023-Jan-02 ~main 2023-Jan-02 - Download Stats:
-
-
0 downloads today
-
0 downloads this week
-
0 downloads this month
-
0 downloads total
-
- Score:
- 0.8
- Short URL:
- betterc-interface.dub.pm