/**************************************************************************** * Copyright 2019 Nreal Techonology Limited. All rights reserved. * * This file is part of NRSDK. * * https://www.nreal.ai/ * *****************************************************************************/ namespace NRKernal { using System; using System.Collections.Generic; /// /// Information about a subsystem that can be queried before creating a subsystem instance. /// public class IntegratedSubsystemDescriptor : ISubsystemDescriptor { protected IntegratedSubsystemDescriptor() { } /// /// A unique string that identifies the subsystem that this Descriptor can create. /// public virtual string id { get; } public ISubsystem subsystem { get; protected set; } public virtual ISubsystem Create() => null; } public class IntegratedSubsystemDescriptor : IntegratedSubsystemDescriptor where TSubsystem : IntegratedSubsystem { protected static Dictionary m_SubsystemDict = new Dictionary(); public IntegratedSubsystemDescriptor() { } public virtual new TSubsystem Create() { if (!m_SubsystemDict.ContainsKey(id)) { try { subsystem = (TSubsystem)Activator.CreateInstance(typeof(TSubsystem), this); m_SubsystemDict.Add(id, (TSubsystem)subsystem); } catch (Exception e) { NRDebugger.Error("Get the instance of Class({0}) faild.", typeof(TSubsystem).FullName); throw e; } } return m_SubsystemDict[id]; } } }