PageRenderTime 25ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/src/storage/ChecksumStream.cpp

https://gitlab.com/admin-github-cloud/cynara
C++ | 71 lines | 36 code | 14 blank | 21 comment | 1 complexity | 541bff6736df667d7ae9c34bb66279f0 MD5 | raw file
  1. /*
  2. * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License
  15. */
  16. /**
  17. * @file src/storage/ChecksumStream.cpp
  18. * @author Pawel Wieczorek <p.wieczorek2@samsung.com>
  19. * @version 1.0
  20. * @brief This file contains ChecksumStream implementation.
  21. */
  22. #include <exception>
  23. #include <unistd.h>
  24. #include <config/PathConfig.h>
  25. #include <storage/ChecksumValidator.h>
  26. #include "ChecksumStream.h"
  27. namespace Cynara {
  28. const char ChecksumStream::m_fieldSeparator(PathConfig::StoragePath::fieldSeparator);
  29. const char ChecksumStream::m_recordSeparator(PathConfig::StoragePath::recordSeparator);
  30. ChecksumStream::~ChecksumStream() {
  31. if (!std::uncaught_exception()) {
  32. save();
  33. }
  34. }
  35. ChecksumStream& ChecksumStream::operator<<(std::ostream& (*manip)(std::ostream&)) {
  36. m_bufStream << manip;
  37. m_outStream << manip;
  38. return *this;
  39. }
  40. void ChecksumStream::open(const std::string &filename, std::ios_base::openmode mode) {
  41. m_outStream.open(filename, mode);
  42. }
  43. bool ChecksumStream::is_open(void) const {
  44. return m_outStream.is_open();
  45. }
  46. std::ios_base::fmtflags ChecksumStream::flags(void) const {
  47. return m_outStream.flags();
  48. }
  49. std::ios_base::fmtflags ChecksumStream::flags(std::ios_base::fmtflags flags) {
  50. return m_outStream.flags(flags);
  51. }
  52. void ChecksumStream::save() {
  53. m_outStream.close();
  54. *m_chsStream << m_filename << m_fieldSeparator << ChecksumValidator::generate(m_bufStream.str())
  55. << m_recordSeparator;
  56. }
  57. } // namespace Cynara