File: util.cpp

package info (click to toggle)
macaulay2 1.21%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 133,096 kB
  • sloc: cpp: 110,377; ansic: 16,306; javascript: 4,193; makefile: 3,821; sh: 3,580; lisp: 764; yacc: 590; xml: 177; python: 140; perl: 114; lex: 65; awk: 3
file content (52 lines) | stat: -rw-r--r-- 1,365 bytes parent folder | download
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
// Copyright 2014-2016  Michael E. Stillman

#include "util.hpp"

M2_string string_std_to_M2(const std::string& s)
{
  // The function M2_tostringn does not modify s.data()...
  return M2_tostringn(const_cast<char *>(s.data()), static_cast<int>(s.size()));
}

std::string string_M2_to_std(const M2_string s)
{
  return std::string((char*)(s->array), s->len);
}

void M2_ArrayString_to_stdvector(M2_ArrayString strs,
                                 std::vector<std::string> &result)
{
  for (size_t i = 0; i < strs->len; i++)
    {
      M2_string a = strs->array[i];
      std::string b((char *)a->array, a->len);
      result.push_back(b);
    }
}

std::vector<std::string> M2_ArrayString_to_stdvector(M2_ArrayString strs)
{
  std::vector<std::string> result;
  for (size_t i = 0; i < strs->len; i++)
    {
      M2_string a = strs->array[i];
      result.emplace_back((char *)a->array, a->len);
    }
  return result;
}

M2_ArrayString toM2ArrayString(const std::vector<std::string>& strs)
{
  int n = static_cast<int>(
      strs.size());  // needed since M2_ArrayString len field is int
  int i;
  M2_ArrayString a = getmemarraytype(M2_ArrayString, n);
  a->len = n;
  for (i = 0; i < n; i++) a->array[i] = M2_tostring(strs[i].c_str());
  return a;
}

// Local Variables:
// compile-command: "make -C $M2BUILDDIR/Macaulay2/e "
// indent-tabs-mode: nil
// End: