linelist.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. LICENSE
  3. -------
  4. Copyright 2005 Nullsoft, Inc.
  5. All rights reserved.
  6. Redistribution and use in source and binary forms, with or without modification,
  7. are permitted provided that the following conditions are met:
  8. * Redistributions of source code must retain the above copyright notice,
  9. this list of conditions and the following disclaimer.
  10. * Redistributions in binary form must reproduce the above copyright notice,
  11. this list of conditions and the following disclaimer in the documentation
  12. and/or other materials provided with the distribution.
  13. * Neither the name of Nullsoft nor the names of its contributors may be used to
  14. endorse or promote products derived from this software without specific prior written permission.
  15. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
  16. IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  17. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  18. CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  19. DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  20. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
  21. IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  22. OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23. */
  24. #ifdef LASER
  25. #include <windows.h>
  26. #include "linelist.h"
  27. class C_LineList : public C_LineListBase
  28. {
  29. private:
  30. int max;
  31. int used;
  32. LineType *linelist;
  33. public:
  34. C_LineList() { max=16384; linelist=(LineType *)malloc(16384*sizeof(LineType)); used=0; };
  35. virtual ~C_LineList() { free(linelist); }
  36. virtual int GetMaxLines(void) { return max; };
  37. virtual int GetUsedLines(void) { return used; };
  38. virtual void SetUsedLines(int usedlines) { used=usedlines; }
  39. virtual void SetLines(LineType *list, int start, int length) { memcpy(linelist+start,list,length*sizeof(LineType)); }
  40. virtual void SetMaxLines(int m);
  41. virtual void ClearLineList(void);
  42. virtual LineType *GetLineList(void);
  43. virtual void AddLine(LineType *line);
  44. void swapcontents(C_LineList *other)
  45. {
  46. {
  47. int tmp;
  48. tmp=max;
  49. max=other->max;
  50. other->max=tmp;
  51. tmp=used;
  52. used=other->used;
  53. other->used=tmp;
  54. }
  55. LineType *tmp;
  56. tmp=linelist;
  57. linelist=other->linelist;
  58. other->linelist=tmp;
  59. }
  60. };
  61. C_LineListBase *createLineList(void)
  62. {
  63. return (C_LineListBase *)new C_LineList();
  64. }
  65. void LineListSwap(C_LineListBase *item1, C_LineListBase *item2)
  66. {
  67. C_LineList *i1=(C_LineList*)item1;
  68. C_LineList *i2=(C_LineList*)item2;
  69. i1->swapcontents(i2);
  70. }
  71. void C_LineList::SetMaxLines(int m)
  72. {
  73. if (m > 16384) m = 16384;
  74. max=m;
  75. if (used > max) ClearLineList();
  76. }
  77. void C_LineList::ClearLineList(void)
  78. {
  79. used=0;
  80. }
  81. LineType *C_LineList::GetLineList(void)
  82. {
  83. return linelist;
  84. }
  85. void C_LineList::AddLine(LineType *line)
  86. {
  87. if (used >= max) return;
  88. memcpy(linelist+used,line,sizeof(LineType));
  89. used++;
  90. }
  91. #endif