1 /* 2 * Copyright (C) 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #include "lang_id/common/fel/workspace.h" 18 19 #include <atomic> 20 #include <string> 21 #include <vector> 22 23 namespace libtextclassifier3 { 24 namespace mobile { 25 26 // static GetFreshTypeId()27int GetFreshTypeId() { 28 // Static local below is initialized the first time this method is run. 29 static std::atomic<int> counter(0); 30 return counter++; 31 } 32 DebugString() const33std::string WorkspaceRegistry::DebugString() const { 34 std::string str; 35 for (auto &it : workspace_names_) { 36 const std::string &type_name = workspace_types_.at(it.first); 37 for (size_t index = 0; index < it.second.size(); ++index) { 38 const std::string &workspace_name = it.second[index]; 39 str.append("\n "); 40 str.append(type_name); 41 str.append(" :: "); 42 str.append(workspace_name); 43 } 44 } 45 return str; 46 } 47 VectorIntWorkspace(int size)48VectorIntWorkspace::VectorIntWorkspace(int size) : elements_(size) {} 49 VectorIntWorkspace(int size,int value)50VectorIntWorkspace::VectorIntWorkspace(int size, int value) 51 : elements_(size, value) {} 52 VectorIntWorkspace(const std::vector<int> & elements)53VectorIntWorkspace::VectorIntWorkspace(const std::vector<int> &elements) 54 : elements_(elements) {} 55 TypeName()56std::string VectorIntWorkspace::TypeName() { return "Vector"; } 57 58 } // namespace mobile 59 } // namespace nlp_saft 60