10225501448 李度 10225101546 陈胤遒 10215501422 高宇菲
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

59 satır
1.4 KiB

  1. // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file. See the AUTHORS file for names of contributors.
  4. #include <stdio.h>
  5. #include "port/port.h"
  6. #include "leveldb/status.h"
  7. namespace leveldb {
  8. Status::Status(Code code, const Slice& msg, const Slice& msg2) {
  9. assert(code != kOk);
  10. state_ = new State(make_pair(code, std::string(msg.data(), msg.size())));
  11. if (!msg2.empty()) {
  12. state_->second.append(": ");
  13. state_->second.append(msg2.data(), msg2.size());
  14. }
  15. }
  16. std::string Status::ToString() const {
  17. if (state_ == NULL) {
  18. return "OK";
  19. } else {
  20. char tmp[30];
  21. const char* type;
  22. switch (state_->first) {
  23. case kOk:
  24. type = "OK";
  25. break;
  26. case kNotFound:
  27. type = "NotFound";
  28. break;
  29. case kCorruption:
  30. type = "Corruption: ";
  31. break;
  32. case kNotSupported:
  33. type = "Not implemented: ";
  34. break;
  35. case kInvalidArgument:
  36. type = "Invalid argument: ";
  37. break;
  38. case kIOError:
  39. type = "IO error: ";
  40. break;
  41. default:
  42. snprintf(tmp, sizeof(tmp), "Unknown code(%d): ",
  43. static_cast<int>(state_->first));
  44. type = tmp;
  45. break;
  46. }
  47. std::string result(type);
  48. if (!state_->second.empty()) {
  49. result.append(state_->second);
  50. }
  51. return result;
  52. }
  53. }
  54. }