static Tags() { Context = new CKTraitContext("ActivityMonitor"); Empty = Context.EmptyTrait; UserConclusion = Context.FindOrCreate("c:User"); GetTextConclusion = Context.FindOrCreate("c:GetText"); MonitorTopicChanged = Context.FindOrCreate("MonitorTopicChanged"); CreateDependentActivity = Context.FindOrCreate("dep:CreateActivity"); StartDependentActivity = Context.FindOrCreate("dep:StartActivity"); }
/// <summary> /// Obtains a <see cref="CKTrait"/> that contains the atomic traits from both this trait and <paramref name="other"/>. /// </summary> /// <param name="other">Trait that must be kept.</param> /// <returns>The resulting trait.</returns> public CKTrait Intersect(CKTrait other) { if (ReferenceEquals(other, this)) { return(this); } if (other == null) { throw new ArgumentNullException("other"); } if (other.Context != _context) { throw new InvalidOperationException(Impl.CoreResources.TraitsMustBelongToTheSameContext); } ListTrait m = new ListTrait(); Process(this, other, null, null, m.TrueAdd); return(_context.FindOrCreate(m)); }
IEnumerable <CKTrait> ComputeFallbacks() { int _currentLength = _tags.Count - 1; Debug.Assert(_currentLength >= 1, "Empty and atomic tags are handled explicitly (EnumWithEmpty)."); if (_currentLength > 1) { int nbTag = _tags.Count; bool[] kept = new bool[nbTag]; CKTrait[] v = new CKTrait[_currentLength]; do { int i = nbTag; while (--i >= _currentLength) { kept[i] = false; } int kMax = i; while (i >= 0) { kept[i--] = true; } do { i = 0; for (int j = 0; j < nbTag; ++j) { if (kept[j]) { v[i++] = _tags[j]; } } Debug.Assert(i == _currentLength, "We kept the right number of tags."); yield return(_context.FindOrCreate(v, i)); }while(Forward(kept, ref kMax)); }while(--_currentLength > 1); } // Special processing for currentLength = 1 (optimization) foreach (CKTrait m in _tags) { yield return(m); } yield return(_context.EmptyTrait); }
/// <summary> /// Simple shortcut to <see cref="CKTraitContext.FindOrCreate(string)"/>. /// </summary> /// <param name="tags">Atomic tag or multiple tags separated by pipes (|).</param> /// <returns>Registered tags.</returns> static public CKTrait Register(string tags) { return(Context.FindOrCreate(tags)); }