PageRenderTime 43ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/llcommon/llfixedbuffer.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 97 lines | 56 code | 16 blank | 25 comment | 2 complexity | 8c455ef7a045f5c24c62df46bbeb26dd MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llfixedbuffer.cpp
  3. *
  4. * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  5. * Second Life Viewer Source Code
  6. * Copyright (C) 2010, Linden Research, Inc.
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation;
  11. * version 2.1 of the License only.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with this library; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. *
  22. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  23. * $/LicenseInfo$
  24. */
  25. #include "linden_common.h"
  26. #include "llfixedbuffer.h"
  27. ////////////////////////////////////////////////////////////////////////////
  28. LLFixedBuffer::LLFixedBuffer(const U32 max_lines)
  29. : LLLineBuffer(),
  30. mMaxLines(max_lines),
  31. mMutex(NULL)
  32. {
  33. mTimer.reset();
  34. }
  35. LLFixedBuffer::~LLFixedBuffer()
  36. {
  37. clear();
  38. }
  39. void LLFixedBuffer::clear()
  40. {
  41. mMutex.lock() ;
  42. mLines.clear();
  43. mAddTimes.clear();
  44. mLineLengths.clear();
  45. mMutex.unlock() ;
  46. mTimer.reset();
  47. }
  48. void LLFixedBuffer::addLine(const std::string& utf8line)
  49. {
  50. LLWString wstring = utf8str_to_wstring(utf8line);
  51. addWLine(wstring);
  52. }
  53. void LLFixedBuffer::addWLine(const LLWString& line)
  54. {
  55. if (line.empty())
  56. {
  57. return;
  58. }
  59. removeExtraLines();
  60. mMutex.lock() ;
  61. mLines.push_back(line);
  62. mLineLengths.push_back((S32)line.length());
  63. mAddTimes.push_back(mTimer.getElapsedTimeF32());
  64. mMutex.unlock() ;
  65. }
  66. void LLFixedBuffer::setMaxLines(S32 max_lines)
  67. {
  68. mMaxLines = max_lines;
  69. removeExtraLines();
  70. }
  71. void LLFixedBuffer::removeExtraLines()
  72. {
  73. mMutex.lock() ;
  74. while ((S32)mLines.size() > llmax((S32)0, (S32)(mMaxLines - 1)))
  75. {
  76. mLines.pop_front();
  77. mAddTimes.pop_front();
  78. mLineLengths.pop_front();
  79. }
  80. mMutex.unlock() ;
  81. }