scenepic 1.1.0
3D Visualization Made Easy
util.h
Go to the documentation of this file.
1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4#ifndef _SCENEPIC_UTIL_H_
5#define _SCENEPIC_UTIL_H_
6
7#include <map>
8#include <sstream>
9#include <string>
10#include <vector>
11
12namespace scenepic
13{
14 template<typename T>
15 void split(const std::string& s, char delim, T result)
16 {
17 std::istringstream iss(s);
18 std::string item;
19 while (std::getline(iss, item, delim))
20 {
21 if (!item.empty())
22 {
23 *result++ = item;
24 }
25 }
26 }
27
28 template<typename T>
30 const std::vector<T>& items,
31 std::vector<T>& unique_items,
32 std::vector<std::size_t>& reverse_index)
33 {
34 if (items.size() == 0)
35 {
36 return;
37 }
38
39 std::map<T, std::size_t> lookup;
40 for (auto& item : items)
41 {
42 if (lookup.count(item))
43 {
44 reverse_index.push_back(lookup[item]);
45 }
46 else
47 {
48 std::size_t index = unique_items.size();
49 lookup[item] = index;
50 unique_items.push_back(item);
51 reverse_index.push_back(index);
52 }
53 }
54 }
55} // namespace scenepic
56
57#endif
Definition: audio_track.h:14
void unique_index(const std::vector< T > &items, std::vector< T > &unique_items, std::vector< std::size_t > &reverse_index)
Definition: util.h:29
void split(const std::string &s, char delim, T result)
Definition: util.h:15