betterc-interface ~main

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 via abstract class instead of interface itself. This happens because simply by using interface keyword, D refuses to build.
  • opCast can't be defined as of now, use getInterface!T. This happens because opCast breaks emplace, 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();
}
Authors:
  • Hipreme
Dependencies:
none
Versions:
1.0.1 2023-Jan-02
1.0.0 2023-Jan-02
~master 2023-Jan-02
~main 2023-Jan-02
Show all 4 versions
Download Stats:
  • 0 downloads today

  • 0 downloads this week

  • 0 downloads this month

  • 8 downloads total

Score:
0.8
Short URL:
betterc-interface.dub.pm