Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to define const getters for djinni?

I define a C++ interface with djinni:

member = interface +c {
    get_id(): string;
    get_name(): string;
}

My inherited implementation uses const getters, i.e.

class MyMemeber: public Member {
  private:
    string id;
    string name;
  public:
    string get_id() const override { return id; }
    string get_name() const override { return name; }
}

This obviously fails to compile, because of const attribute. Can I teach djinni to generate the base interface with const getters, too?

like image 558
Alex Cohn Avatar asked Apr 18 '16 13:04

Alex Cohn


1 Answers

It is nowhere documented though from the very beginning djinni generates const methods (line 295 of src/source/CppGenerator.scala). Just add const in front of method signature in idl file:

member = interface +c {
    const get_id(): string;
    const get_name(): string;
}

I think it would be good idea to pull request tests for this feature (and some docs), currently only const fields are tested.

like image 159
mkk Avatar answered Nov 05 '22 15:11

mkk