Promotion.vala 844 B

123456789101112131415161718192021222324252627282930
  1. using Invercargill.DataStructures;
  2. namespace Invercargill {
  3. private static Dictionary<Type, Type> promotion_registry = null;
  4. public static void register_promotion(Type generic, Type promotion) {
  5. if(promotion_registry == null) {
  6. promotion_registry = new Dictionary<Type, Type>();
  7. }
  8. promotion_registry[generic] = promotion;
  9. }
  10. public static void resolve_promotion<T>(ref Type type) {
  11. if(promotion_registry == null) {
  12. return;
  13. }
  14. Type promotion;
  15. if(promotion_registry.try_get(typeof(T), out promotion)) {
  16. type = promotion;
  17. }
  18. }
  19. public interface Promotion<T> {
  20. public abstract Enumerable<T> wrap(Enumerable<T> enumerable) throws PromotionError;
  21. public abstract bool can_wrap(Type element_type);
  22. }
  23. }