The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

ObjectGroup.vala in /libsvgbird

This file is a part of the Birdfont project.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
Circle boundaries heads/master
1 /* 2 Copyright (C) 2015 Johan Mattsson 3 4 This library is free software; you can redistribute it and/or modify 5 it under the terms of the GNU Lesser General Public License as 6 published by the Free Software Foundation; either version 3 of the 7 License, or (at your option) any later version. 8 9 This library is distributed in the hope that it will be useful, but 10 WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 Lesser General Public License for more details. 13 */ 14 15 namespace SvgBird { 16 17 public class ObjectGroup : GLib.Object { 18 public Gee.ArrayList<Object> objects; 19 20 public int size { 21 get { 22 return objects.size; 23 } 24 } 25 26 public ObjectGroup () { 27 objects = new Gee.ArrayList<Object> (); 28 } 29 30 public Object get_object (int index) { 31 if (unlikely (index < 0 || index >= size)) { 32 warning ("Index out of bounds."); 33 return new EmptyObject (); 34 } 35 36 return objects.get (index); 37 } 38 39 public int index_of (Object o) { 40 return objects.index_of (o); 41 } 42 43 public Gee.Iterator<Object> iterator () { 44 return objects.iterator (); 45 } 46 47 public void remove (Object p) { 48 objects.remove (p); 49 } 50 51 public void add (Object p) { 52 objects.add (p); 53 } 54 55 public void clear () { 56 objects.clear (); 57 } 58 59 public void append (ObjectGroup group) { 60 foreach (Object o in group.objects) { 61 objects.add (o); 62 } 63 } 64 65 public ObjectGroup copy () { 66 ObjectGroup objects_copy = new ObjectGroup (); 67 68 foreach (Object o in objects) { 69 objects_copy.add (o.copy ()); 70 } 71 72 return objects_copy; 73 } 74 75 public void print_objects () { 76 foreach (Object o in objects) { 77 stdout.printf (o.to_string ()); 78 stdout.printf ("\n"); 79 } 80 } 81 } 82 83 } 84