this repo has no description
at develop 1.1 kB view raw
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ 2 3/* 4 * Main authors: 5 * Guido Tack <guido.tack@monash.edu> 6 */ 7 8/* This Source Code Form is subject to the terms of the Mozilla Public 9 * License, v. 2.0. If a copy of the MPL was not distributed with this 10 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 11 12#include <minizinc/aststring.hh> 13 14#include <iostream> 15 16#ifndef HAS_MEMCPY_S 17namespace { 18void memcpy_s(char* dest, size_t, const char* src, size_t count) { memcpy(dest, src, count); } 19} // namespace 20#endif 21 22namespace MiniZinc { 23 24ASTStringO::ASTStringO(const std::string& s) : ASTChunk(s.size() + sizeof(size_t) + 1) { 25 memcpy_s(_data + sizeof(size_t), s.size() + 1, s.c_str(), s.size()); 26 *(_data + sizeof(size_t) + s.size()) = 0; 27 std::hash<std::string> h; 28 reinterpret_cast<size_t*>(_data)[0] = h(s); 29} 30 31ASTStringO* ASTStringO::a(const std::string& s) { 32 ASTStringO* as = static_cast<ASTStringO*>(alloc(1 + sizeof(size_t) + s.size())); 33 new (as) ASTStringO(s); 34 return as; 35} 36 37} // namespace MiniZinc