relation.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. Copyright (c) 2010, Florian Reuter
  3. All rights reserved.
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions
  6. are met:
  7. * Redistributions of source code must retain the above copyright
  8. notice, this list of conditions and the following disclaimer.
  9. * Redistributions in binary form must reproduce the above copyright
  10. notice, this list of conditions and the following disclaimer in
  11. the documentation and/or other materials provided with the
  12. distribution.
  13. * Neither the name of Florian Reuter nor the names of its contributors
  14. may be used to endorse or promote products derived from this
  15. software without specific prior written permission.
  16. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  17. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  18. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  19. FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  20. COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  21. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  22. BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  23. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  24. CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  25. STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  26. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  27. OF THE POSSIBILITY OF SUCH DAMAGE.
  28. */
  29. /** @file opc/relation.h
  30. */
  31. #include <opc/config.h>
  32. #ifndef OPC_RELATION_H
  33. #define OPC_RELATION_H
  34. #ifdef __cplusplus
  35. extern "C" {
  36. #endif
  37. /**
  38. Indentifier for an OPC relation.
  39. */
  40. typedef opc_uint32_t opcRelation;
  41. /**
  42. Constant which represents an invalid relation.
  43. */
  44. #define OPC_RELATION_INVALID (-1)
  45. /**
  46. Find a relation originating from \c part in \c container with \c relationId and/or \c mimeType.
  47. If \c part is OPC_PART_INVALID then part represents the root part.
  48. @param[in] relationId The relationId (e.g. "rId1") or NULL.
  49. @param[in] mimeType The mimeType or NULL.
  50. */
  51. opcRelation opcRelationFind(opcContainer *container, opcPart part, const xmlChar *relationId, const xmlChar *mimeType);
  52. /**
  53. Deleted the relation from the container.
  54. \see opcRelationFind.
  55. */
  56. opc_error_t opcRelationDelete(opcContainer *container, opcPart part, const xmlChar *relationId, const xmlChar *mimeType);
  57. /**
  58. Returns the first relation.
  59. The following code will dump all relations:
  60. \code
  61. for(opcPart part=opcPartGetFirst(c);OPC_PART_INVALID!=part;part=opcPartGetNext(c, part)) {
  62. for(opcRelation rel=opcRelationFirst(part, c);
  63. OPC_PART_INVALID!=rel;
  64. rel=opcRelationNext(c, rel)) {
  65. opcPart internal_target=opcRelationGetInternalTarget(c, part, rel);
  66. const xmlChar *external_target=opcRelationGetExternalTarget(c, part, rel);
  67. const xmlChar *target=(NULL!=internal_target?internal_target:external_target);
  68. const xmlChar *prefix=NULL;
  69. opc_uint32_t counter=-1;
  70. const xmlChar *type=NULL;
  71. opcRelationGetInformation(c, part, rel, &prefix, &counter, &type);
  72. if (-1==counter) { // no counter after prefix
  73. printf("%s;%s;%s;%s\n", part, prefix, target, type);
  74. } else {
  75. printf("%s;%s%i;%s;%s\n", part, prefix, counter, target, type);
  76. }
  77. }
  78. }
  79. \endcode
  80. */
  81. opcRelation opcRelationFirst(opcContainer *container, opcPart part);
  82. /**
  83. \see opcRelationFirst
  84. */
  85. opcRelation opcRelationNext(opcContainer *container, opcPart part, opcRelation relation);
  86. /**
  87. Returns the internal target.
  88. \note To test for an external target use opcRelationGetExternalTarget.
  89. \see opcRelationGetExternalTarget
  90. */
  91. opcPart opcRelationGetInternalTarget(opcContainer *container, opcPart part, opcRelation relation);
  92. /**
  93. Returns the external target or NULL if it is an internal target.
  94. The string is interned. Must not be freed.
  95. \see opcRelationGetExternalTarget
  96. */
  97. const xmlChar *opcRelationGetExternalTarget(opcContainer *container, opcPart part, opcRelation relation);
  98. /**
  99. Returns the relations type.
  100. The string is interned. Must not be freed.
  101. */
  102. const xmlChar *opcRelationGetType(opcContainer *container, opcPart part, opcRelation relation);
  103. /**
  104. Get information about a relation.
  105. \see opcRelationFirst
  106. */
  107. void opcRelationGetInformation(opcContainer *container, opcPart part, opcRelation relation, const xmlChar **prefix, opc_uint32_t *counter, const xmlChar **type);
  108. /**
  109. Add a relation to \c container from \c src part to \c dest part with id \c rid and type \c type.
  110. */
  111. opc_uint32_t opcRelationAdd(opcContainer *container, opcPart src, const xmlChar *rid, opcPart dest, const xmlChar *type);
  112. /**
  113. Add an external relation to \c container from \c src part to \c target URL with id \c rid and type \c type.
  114. */
  115. opc_uint32_t opcRelationAddExternal(opcContainer *container, opcPart src, const xmlChar *rid, const xmlChar *target, const xmlChar *type);
  116. #ifdef __cplusplus
  117. } /* extern "C" */
  118. #endif
  119. #endif /* OPC_RELATION_H */