1 // The MIT License (MIT)
2 //
3 // 	Copyright (c) 2015 Sergey Makeev, Vadim Slyusarev
4 //
5 // 	Permission is hereby granted, free of charge, to any person obtaining a copy
6 // 	of this software and associated documentation files (the "Software"), to deal
7 // 	in the Software without restriction, including without limitation the rights
8 // 	to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 // 	copies of the Software, and to permit persons to whom the Software is
10 // 	furnished to do so, subject to the following conditions:
11 //
12 //  The above copyright notice and this permission notice shall be included in
13 // 	all copies or substantial portions of the Software.
14 //
15 // 	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // 	IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // 	FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 // 	AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // 	LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // 	OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 // 	THE SOFTWARE.
22 
23 #pragma once
24 
25 
26 namespace MT
27 {
28 	//Task group ID
29 	class TaskGroup
30 	{
31 		int16 id;
32 
33 	public:
34 
35 		static const int16 MT_MAX_GROUPS_COUNT = 256;
36 
37 		enum PredefinedValues
38 		{
39 			DEFAULT = 0,
40 			INVALID = -1,
41 			ASSIGN_FROM_CONTEXT = -2
42 		};
43 
44 
45 		TaskGroup()
46 		{
47 			id = INVALID;
48 		}
49 
50 		explicit TaskGroup(PredefinedValues v)
51 		{
52 			id = (int16)v;
53 		}
54 
55 		explicit TaskGroup(int16 _id)
56 		{
57 			id = _id;
58 		}
59 
60 		static TaskGroup Default()
61 		{
62 			return TaskGroup(DEFAULT);
63 		}
64 
65 		TaskGroup & operator= (const PredefinedValues & v)
66 		{
67 			id = (int16)v;
68 			return *this;
69 		}
70 
71 		bool operator== (const PredefinedValues & v) const
72 		{
73 			return (id == v);
74 		}
75 
76 		bool operator== (const TaskGroup & other) const
77 		{
78 			return (id == other.id);
79 		}
80 
81 		bool operator!= (const TaskGroup & other) const
82 		{
83 			return (id != other.id);
84 		}
85 
86 		int GetValidIndex() const
87 		{
88 			MT_ASSERT(IsValid(), "Try to get invalid index");
89 
90 			return id;
91 		}
92 
93 		bool IsValid() const
94 		{
95 			if (id == INVALID)
96 				return false;
97 
98 			if (id == ASSIGN_FROM_CONTEXT)
99 				return false;
100 
101 			return (id >= 0 && id < MT_MAX_GROUPS_COUNT);
102 		}
103 
104 
105 
106 	};
107 
108 
109 
110 }
111