Autodesk / Autodesk/AutomaticComponentToolkit

Add template classes

オープン
#144 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
Go
スター
53
フォーク
26
PR マージ指標
30日以内にマージされた PR はありません

説明

Currently ACT does not support generic classes (aka template classes) which makes it hard to define certain types such as (type-safe) generic containers and algorithms.

For example, to define types like `Map`, `Map`, and `Map` in the API today, you would need to define the following:

```xml












```

This quickly becomes unmaintainable as for N instantiations you need to:

* Copy-paste and adjust the method definitions N times
* Maintain N implementation classes by:
* Writing the same code N times, or
* Writing a generic `Map` class yourself and inheriting from that N times (something like `class StringBarMap : public Map`)

Instead, ACT could provide support for generic classes, and it could look something like this (following previous discussions with @martinweismann and @alexanderoster):

```xml



























```

The implementation stubs could then be generated as follows:

```c++
// Implementation Stubs
namespace Component { namespace Impl {

template
class CMap
{
public:
virtual void Add(TKey Key, TValue Value);

virtual TValue Get(TKey Key);

virtual void GetOut(TKey Key, TValue *pValue);

virtual void Clear();

virtual Component_uint32 Count();
};

class IntFooMap : public CMap
{
/* instantiates to:
virtual void Add(Component_int32 Key, IFoo * Value);

virtual IFoo * Get(Component_int32 Key);

virtual void GetOut(Component_int32 Key, IFoo **pValue);

virtual void Clear();

virtual Component_uint32 Count();
*/
};

class StringBarMap : public CMap
{
/* instantiates to:
virtual void Add(String * Key, IBar * Value);

virtual IBar * Get(String * Key);

virtual void GetOut(String * Key, IBar **pValue);

virtual void Clear();

virtual Component_uint32 Count();
*/
};

class IntDoubleMap : public CMap
{
/* instantiates to:
virtual void Add(Component_int32 Key, double Value);

virtual double Get(Component_int32 Key);

virtual void GetOut(Component_int32 Key, double *pValue);

virtual void Clear();

virtual Component_uint32 Count();
*/
};

}} // namespace Component::Impl
```

And the bindings:

```c++
// Bindings
namespace Component { namespace Binding {

class CMap
{
public:
virtual void Clear();

virtual Component_uint32 Count();
};

class IntFooMap : public CMap
{
virtual void Add(Component_int32 Key, IFoo * Value);

virtual IFoo * Get(Component_int32 Key);

virtual void GetOut(Component_int32 Key, IFoo **pValue);
};

class StringBarMap : public CMap
{
virtual void Add(String * Key, IBar * Value);

virtual IBar * Get(String * Key);

virtual void GetOut(String * Key, IBar **pValue);
};

class IntDoubleMap : public CMap
{
virtual void Add(Component_int32 Key, double Value);

virtual double Get(Component_int32 Key);

virtual void GetOut(Component_int32 Key, double *pValue);
};

}} // namespace Component::Binding
```

The API author would then only need to implement the template class CMap once.

Notes:
* Only works with strings if they're wrapped in a class
* Already a need for string wrapper class
* Can't support string without wrapper class because of different in/out/return types (`const std::string&` / `std::string &` / `std::string`)
* Template class signatures would differ from the simple / class types, won't work.
* Ref counting, need to check if type is a pointer or not to decide whether or not to call IncRefCount/DecRefCount.
* Provide a helper function with specializations for class / simple types
* Concepts
* Example: key type for map, how to compare?
* `pLhs->Compare(pRhs)`?
* `pLhs < pRhs`?
* Leave it up to the API author, C++ (pre C++20) didn't have support for Concepts either and relied on documentation
* API author can choose to write template functions with specializations like (ACT could document an example)
```c++
template
struct compare_helper {
static int compare(T lhs, T rhs);
};

template
struct compare_helper>>> {
static int compare(Comparable pLhs, Comparable pRhs) {
static_assert(std::is_member_function_pointer::Compare)>::value,
"Type does not implement Comparable concept (Comparable::Compare is not a member function).");
return pLhs->Compare(pRhs);
}
};

template
struct compare_helper>> {
static int compare(Comparable lhs, Comparable rhs) {
return lhs - rhs;
}
};

template
int compare(T lhs, T rhs) {
return compare_helper::compare(lhs,rhs);
}
// compare(pObject1, pObject2) => compiles only if pObject1 has Compare method
// compare(1,2)
```

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

ソースファイル、テスト、またはエントリポイントは指定されていません。まず、提案されている XML の templateclass/templateparam スキーマと、生成された C++ 実装およびバインディングの例を確認します。示されたインスタンス化に対して、ジェネリッククラスを宣言でき、その実装スタブとバインディングが生成されれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
cpp
領域
tooling
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
30/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。