stream.h 1.9 KB
Newer Older
Y
Yan Chunwei 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
// Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#pragma once

#ifdef LITE_ON_TINY_PUBLISH
#include <stdlib.h>
#include <string>
#else
#include <iomanip>
#include <iostream>
#include <sstream>
#endif

#ifdef LITE_ON_TINY_PUBLISH
namespace paddle {
namespace lite {

namespace replace_stl {

32 33 34 35 36 37 38
struct LiteIoWidth {
  explicit LiteIoWidth(int value) : width(value) {}
  int width;
};

static LiteIoWidth setw(int width) { return LiteIoWidth(width); }

Y
Yan Chunwei 已提交
39 40 41
class ostream {
 public:
  ostream() {}
42
  explicit ostream(const std::string& x) : data_(x) {}
Y
Yan Chunwei 已提交
43 44
  ~ostream() {}

45
  const char* c_str() { return data_.c_str(); }
Y
Yan Chunwei 已提交
46

47
  const std::string& str() { return data_; }
Y
Yan Chunwei 已提交
48
  const std::string& str(const std::string& x) {
49 50
    data_ = x;
    return data_;
Y
Yan Chunwei 已提交
51 52 53 54 55 56 57 58 59
  }

  template <typename T>
  ostream& operator<<(const T& obj);

  template <typename T>
  ostream& operator<<(const T* obj);

 private:
60
#ifdef LITE_WITH_LOG
61
  void pad(const std::string& text);
62
#endif
63 64
  std::string data_;
  int display_width_{-1};  // -1 refers to no setting
Y
Yan Chunwei 已提交
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
};

class stringstream : public ostream {
 public:
  stringstream() = default;

  ~stringstream() {}

  explicit stringstream(const std::string& x) : ostream(x) {}  // NOLINT

  void precision(int x) {}
};

}  // namespace replace_stl

}  // namespace lite
}  // namespace paddle

// replace namespace
namespace STL = paddle::lite::replace_stl;
#else
namespace STL = std;
#endif