export.h 1.4 KB
Newer Older
D
dolphin8 已提交
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
#pragma once

#include <iostream>
#include <vector>
#include <memory>
#include <string>
#include <ostream>
#include <fstream>

#include "framework/loader.h"
#include "framework/executor.h"
#include "framework/scope.h"
#include "framework/program/program_desc.h"

// using paddle_mobile::framework::ProgramDesc;
// using paddle_mobile::framework::Scope;

using ProgramPtr = std::shared_ptr<paddle_mobile::framework::ProgramDesc>;
using ScopePtr = std::shared_ptr<paddle_mobile::framework::Scope>;

void export_nodejs(ProgramPtr program, ScopePtr scope, std::ostream & os = std::cout);
void export_scope(ProgramPtr program, ScopePtr scope, const std::string & dirname = ".");


template <typename T>
inline std::string var2str(const T & v) {
  return std::to_string(v);
}

template <>
inline std::string var2str(const std::string & v) {
  return "\"" + v + "\"";
}

inline std::string var2str(const char* v) {
  return var2str<std::string>(v);
}

inline std::string var2str(const bool v) {
  return v ? "true" : "false";
}

template <typename T>
std::string var2str(const std::vector<T> & v) {
  std::string r = "[";
  auto s = v.size();
  for (int i = 0; i < s; i++) {
    if (i) r += ", ";
    r += var2str(v[i]);
  }
  return r + "]";
}

struct VarVisitor {
  using type_t = decltype(var2str(0));

  template <typename T>
  type_t operator()(const T & v) {
    return var2str(v);
  }
};