Device
、、、Register
およびの3 つのクラスがWriteOnlyPolicy
次のように定義されています。
デバイス
class Device
{
public:
template<class Register>
inline void write(typename Register::value_type value)
{
Register::writeRegister(value, this);
}
protected:
// limit device-specific API calls to this function
virtual void writeDeviceRegister(uint64_t address, uint64_t value) = 0;
};
登録
template<uint64_t ADDRESS, class ValueType, template<class> class AccessPolicy>
struct Register : public AccessPolicy<ValueType>
{
using value_type = ValueType;
using access_policy = AccessPolicy<ValueType>;
static void writeRegister(value_type value, Device* device)
{
access_policy::write(ADDRESS, device, value);
}
}
書き込み専用ポリシー
template<typename value_type>
class WriteOnlyPolicy
{
protected:
static void write(uint64_t ADDRESS, Device* device, value_type value)
{
// convert from a value_type to a uint64_t...
// Shift/mask as needed...
device->writeDeviceRegister(ADDRESS, value);
}
};
Register
WriteOnlyPolicy
このスキームで実際にインスタンス化されることはありませんが、ポリシーでクラスの保護された関数を呼び出す必要がありますwriteDeviceRegister
。デバイス固有の実装ではなく、クラスのユーザーDevice
にのみ関数を公開したいので、その関数を公開したくありません。write
Device
友達になりたいRegister::access_policy
(この場合はWriteOnlyPolicy
、テンプレート引数として指定されたクラス) を許可するために、テンプレート クラスの依存型名を友達にする構文がわかりません。これは可能ですか?
などfriend
のクラスに宣言を入れることを考えましたDevice
template<uint64_t a, class b, template<class> class c>
friend typename Register<a,b,c>::access_policy;
トリックを行いますが、エラーが発生します
エラー: ';' の前に unqualified-id が必要です トークン