public CartoSelector(IEnumerable<Element> elements, Env env)
      : base(elements)
    {
      m_filters = new CartoFilterSet();
      m_zooms = new NodeList<CartoZoomElement>();
      m_elements = new NodeList<CartoElement>();

      m_conditions = 0;
      if (env == null)
      	env = new Env(); // TODO
      
      foreach (Element elem in elements)
      {
        if (elem is CartoFilterElement)
        {
          m_filters.Add(elem as CartoFilterElement, env);
          m_conditions++;
        }
        else if (elem is CartoZoomElement)
        {
          m_zooms.Add(elem as CartoZoomElement);
          m_conditions++;
        }
        else if (elem is CartoAttachmentElement)
          m_attachment = (elem as CartoAttachmentElement).Value;
        else
          m_elements.Add((CartoElement)elem);
      }
    }
Beispiel #2
0
        public CartoSelector(IEnumerable <Element> elements, Env env)
            : base(elements)
        {
            m_filters  = new CartoFilterSet();
            m_zooms    = new NodeList <CartoZoomElement>();
            m_elements = new NodeList <CartoElement>();

            m_conditions = 0;
            if (env == null)
            {
                env = new Env(); // TODO
            }
            foreach (Element elem in elements)
            {
                if (elem is CartoFilterElement)
                {
                    m_filters.Add(elem as CartoFilterElement, env);
                    m_conditions++;
                }
                else if (elem is CartoZoomElement)
                {
                    m_zooms.Add(elem as CartoZoomElement);
                    m_conditions++;
                }
                else if (elem is CartoAttachmentElement)
                {
                    m_attachment = (elem as CartoAttachmentElement).Value;
                }
                else
                {
                    m_elements.Add((CartoElement)elem);
                }
            }
        }
        public object CloneWith(CartoFilterSet other, Env env)
        {
            List <CartoFilterElement> additions = null;

            if (m_filters.Count > 0)
            {
                foreach (KeyValuePair <string, CartoFilterElement> kv in other.m_filters)
                {
                    string id     = kv.Key;
                    object status = this.Addable(kv.Value, env);
                    if (status != null)
                    {
                        if ((bool)status == false)
                        {
                            return(false);
                        }
                        if ((bool)status == true)
                        {
                            // Adding the filter will override another value.
                            if (additions == null)
                            {
                                additions = new List <CartoFilterElement>();
                            }
                            additions.Add(other.m_filters[id]);
                        }
                    }
                }
            }
            else
            {
                if (other.m_filters.Count > 0)
                {
                    additions = new List <CartoFilterElement>(other.m_filters.Count);
                    foreach (KeyValuePair <string, CartoFilterElement> kv in other.m_filters)
                    {
                        additions.Add(other.m_filters[kv.Key]);
                    }
                }
            }

            // Adding the other filters doesn't make this filterset invalid, but it
            // doesn't add anything to it either.
            if (additions == null)
            {
                return(null);
            }

            // We can successfully add all filters. Now clone the filterset and add the
            // new rules.
            var clone = new CartoFilterSet();

            // We can add the rules that are already present without going through the
            // add function as a Filterset is always in it's simplest canonical form.
            foreach (KeyValuePair <string, CartoFilterElement> kv1 in m_filters)
            {
                CartoFilterElement filter = kv1.Value;
                clone.m_filters[kv1.Key] = filter;
            }

            // Only add new filters that actually change the filter.
            //while (id = additions.shift()) {
            foreach (CartoFilterElement id in additions)
            {
                clone.Add(id, env);
            }

            return(clone);
        }
    public object CloneWith(CartoFilterSet other, Env env)
    {
      List<CartoFilterElement> additions = null;

      if (m_filters.Count > 0)
      {
        foreach (KeyValuePair<string, CartoFilterElement> kv in other.m_filters)
        {
          string id = kv.Key;
          object status = this.Addable(kv.Value, env);
          if (status != null)
          {
            if ((bool)status == false)
            {
              return false;
            }
            if ((bool)status == true)
            {
              // Adding the filter will override another value.
              if (additions == null)
                additions = new List<CartoFilterElement>();
              additions.Add(other.m_filters[id]);
            }
          }
        }
      }
      else
      {
        if (other.m_filters.Count > 0)
        {
          additions = new List<CartoFilterElement>(other.m_filters.Count);
          foreach (KeyValuePair<string, CartoFilterElement> kv in other.m_filters)
            additions.Add(other.m_filters[kv.Key]);
        }
      }

      // Adding the other filters doesn't make this filterset invalid, but it
      // doesn't add anything to it either.
      if (additions == null) return null;

      // We can successfully add all filters. Now clone the filterset and add the
      // new rules.
      var clone = new CartoFilterSet();

      // We can add the rules that are already present without going through the
      // add function as a Filterset is always in it's simplest canonical form.
      foreach (KeyValuePair<string, CartoFilterElement> kv1 in m_filters)
      {
      	  CartoFilterElement filter = kv1.Value;
      	  clone.m_filters[kv1.Key] = filter;
      }

      // Only add new filters that actually change the filter.
      //while (id = additions.shift()) {
      foreach (CartoFilterElement id in additions)
      {
      	clone.Add(id, env);
      }

      return clone;
    }