field.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***************************************************************************
  19. * *
  20. * Project Name : Westwood Auto Registration App *
  21. * *
  22. * File Name : FIELD.H *
  23. * *
  24. * Programmer : Philip W. Gorrow *
  25. * *
  26. * Start Date : 04/22/96 *
  27. * *
  28. * Last Update : April 22, 1996 [PWG] *
  29. * *
  30. * This module takes care of maintaining the field list used to process *
  31. * packets. *
  32. * *
  33. *-------------------------------------------------------------------------*
  34. * Functions: *
  35. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  36. #define FIELD_HEADER_SIZE (sizeof(FieldClass) - (sizeof(void *) * 2))
  37. #define TYPE_CHAR 1
  38. #define TYPE_UNSIGNED_CHAR 2
  39. #define TYPE_SHORT 3
  40. #define TYPE_UNSIGNED_SHORT 4
  41. #define TYPE_LONG 5
  42. #define TYPE_UNSIGNED_LONG 6
  43. #define TYPE_STRING 7
  44. #define TYPE_CHUNK 20
  45. class PacketClass;
  46. class FieldClass
  47. {
  48. public:
  49. friend PacketClass;
  50. //
  51. // Define constructors to be able to create all the different kinds
  52. // of fields.
  53. //
  54. FieldClass(void) {};
  55. FieldClass(char *id, char data);
  56. FieldClass(char *id, unsigned char data);
  57. FieldClass(char *id, short data);
  58. FieldClass(char *id, unsigned short data);
  59. FieldClass(char *id, long data);
  60. FieldClass(char *id, unsigned long data);
  61. FieldClass(char *id, char *data);
  62. FieldClass(char *id, void *data, int length);
  63. ~FieldClass();
  64. // Change the field contents
  65. void Set(char *id, char data);
  66. void Set(char *id, unsigned char data);
  67. void Set(char *id, short data);
  68. void Set(char *id, unsigned short data);
  69. void Set(char *id, long data);
  70. void Set(char *id, unsigned long data);
  71. void Set(char *id, char *data);
  72. void Set(char *id, void *data, int length);
  73. int Get_Type(void); // get the datatype of this field
  74. unsigned short Get_Size(void) { return Size; }
  75. void Host_To_Net(void);
  76. void Net_To_Host(void);
  77. private:
  78. void Clear(void); // dealloc mem & zero safely
  79. char ID[4]; // id value of this field
  80. unsigned short DataType; // id of the data type we are using
  81. unsigned short Size; // size of the data portion of this field
  82. void *Data; // pointer to the data portion of this field
  83. FieldClass *Next; // pointer to the next field in the field list
  84. };