tc_dyn_object.cpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /**
  2. * Tencent is pleased to support the open source community by making Tars available.
  3. *
  4. * Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved.
  5. *
  6. * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
  7. * in compliance with the License. You may obtain a copy of the License at
  8. *
  9. * https://opensource.org/licenses/BSD-3-Clause
  10. *
  11. * Unless required by applicable law or agreed to in writing, software distributed
  12. * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
  13. * CONDITIONS OF ANY KIND, either express or implied. See the License for the
  14. * specific language governing permissions and limitations under the License.
  15. */
  16. #include "util/tc_dyn_object.h"
  17. #include <string.h>
  18. namespace tars
  19. {
  20. /**********************************TC_DYN_RuntimeClass定义***********************************/
  21. TC_DYN_RuntimeClass* TC_DYN_RuntimeClass::pFirstClass = NULL;
  22. TC_DYN_Object* TC_DYN_RuntimeClass::createObject()
  23. {
  24. if (m_pfnCreateObject == NULL)
  25. {
  26. return NULL;
  27. }
  28. TC_DYN_Object* pObject = (*m_pfnCreateObject)();
  29. {
  30. return pObject;
  31. }
  32. }
  33. TC_DYN_RuntimeClass* TC_DYN_RuntimeClass::load(const char *szClassName)
  34. {
  35. TC_DYN_RuntimeClass* pClass;
  36. for (pClass = pFirstClass; pClass != NULL; pClass = pClass->m_pNextClass)
  37. {
  38. if (strcmp(szClassName, pClass->m_lpszClassName) == 0)
  39. return pClass;
  40. }
  41. return NULL;
  42. }
  43. /**********************************szTC_DYN_Object定义***********************************/
  44. TC_DYN_RuntimeClass TC_DYN_Object::classTC_DYN_Object =
  45. {
  46. (char*)"TC_DYN_Object",
  47. sizeof(TC_DYN_Object),
  48. NULL,
  49. NULL,
  50. NULL
  51. };
  52. static TC_DYN_Init _init_TC_DYN_Object(&TC_DYN_Object::classTC_DYN_Object);
  53. TC_DYN_RuntimeClass* TC_DYN_Object::GetRuntimeClass() const
  54. {
  55. return &TC_DYN_Object::classTC_DYN_Object;
  56. }
  57. bool TC_DYN_Object::isKindOf(const TC_DYN_RuntimeClass* pClass) const
  58. {
  59. TC_DYN_RuntimeClass* pClassThis = GetRuntimeClass();
  60. while (pClassThis != NULL)
  61. {
  62. if (pClassThis == pClass)
  63. {
  64. return true;
  65. }
  66. pClassThis = pClassThis->m_pBaseClass;
  67. }
  68. return false;
  69. }
  70. }