StreamDesc.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #region MIT License
  2. /*Copyright (c) 2012 Robert Rouhani <robert.rouhani@gmail.com>
  3. SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
  4. Permission is hereby granted, free of charge, to any person obtaining a copy of
  5. this software and associated documentation files (the "Software"), to deal in
  6. the Software without restriction, including without limitation the rights to
  7. use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
  8. of the Software, and to permit persons to whom the Software is furnished to do
  9. so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in all
  11. copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  18. SOFTWARE.*/
  19. #endregion
  20. using System;
  21. using System.Runtime.InteropServices;
  22. using SharpFont.Internal;
  23. namespace SharpFont
  24. {
  25. /// <summary>
  26. /// A union type used to store either a long or a pointer. This is used to store a file descriptor or a ‘FILE*’ in
  27. /// an input stream.
  28. /// </summary>
  29. public class StreamDesc
  30. {
  31. #region Fields
  32. private IntPtr reference;
  33. private StreamDescRec rec;
  34. #endregion
  35. #region Constructors
  36. internal StreamDesc(IntPtr reference)
  37. {
  38. Reference = reference;
  39. }
  40. internal StreamDesc(IntPtr reference, IntPtr offset)
  41. : this(new IntPtr(reference.ToInt64() + offset.ToInt64()))
  42. {
  43. }
  44. #endregion
  45. #region Properties
  46. /// <summary>
  47. /// Gets the <see cref="StreamDesc"/> as a file descriptor.
  48. /// </summary>
  49. public int Value
  50. {
  51. get
  52. {
  53. return (int)rec.value;
  54. }
  55. }
  56. /// <summary>
  57. /// Gets the <see cref="StreamDesc"/> as an input stream (FILE*).
  58. /// </summary>
  59. public IntPtr Pointer
  60. {
  61. get
  62. {
  63. return rec.pointer;
  64. }
  65. }
  66. internal IntPtr Reference
  67. {
  68. get
  69. {
  70. return reference;
  71. }
  72. set
  73. {
  74. reference = value;
  75. rec = PInvokeHelper.PtrToStructure<StreamDescRec>(reference);
  76. }
  77. }
  78. #endregion
  79. }
  80. }