# Copyright (c) 2014, German Neuroinformatics Node (G-Node)
#
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted under the terms of the BSD License. See
# LICENSE file in the root of the Project.

from __future__ import (absolute_import, division, print_function, unicode_literals)

try:
    from nixio.core import DataArray, MultiTag, Tag
except ImportError:
    DataArray = None
    MultiTag = None
    Tag = None
from nixio.util.inject import inject
from nixio.util.proxy_list import RefProxyList


class RefSourceProxyList(RefProxyList):

    def __init__(self, obj):
        super(RefSourceProxyList, self).__init__(obj, "_source_count", "_get_source_by_id",
                    "_get_source_by_pos", "_remove_source_by_id", "_add_source_by_id")

_sources_doc = """
Getter for sources.
"""

def _get_sources(self):
    if not hasattr(self, "_sources"):
        setattr(self, "_sources", RefSourceProxyList(self))
    return self._sources


class DataArraySourcesMixin(object):

    sources = property(_get_sources, None, None, _sources_doc)


class MultiTagSourcesMixin(object):

    sources = property(_get_sources, None, None, _sources_doc)


class TagSourcesMixin(object):

    sources = property(_get_sources, None, None, _sources_doc)


inject((DataArray,), dict(DataArraySourcesMixin.__dict__))
inject((MultiTag,), dict(MultiTagSourcesMixin.__dict__))
inject((Tag,), dict(TagSourcesMixin.__dict__))

@@ -394,20 +394,107 @@
 rray
-, MultiTag, 
+ as CDataArray%0A    from nixio.core import MultiTag as CMultiTag%0A    from nixio.core import Tag as C
 Tag%0A
@@ -517,16 +517,17 @@
 or:%0A    
+C
 DataArra
@@ -539,16 +539,17 @@
 one%0A    
+C
 MultiTag
@@ -560,16 +560,17 @@
 one%0A    
+C
 Tag = No
@@ -572,16 +572,68 @@
  = None%0A
+%0Afrom nixio.pycore import DataArray, MultiTag, Tag%0A%0A
 from nix
@@ -1473,16 +1473,27 @@
 taArray,
+ CDataArray
 ), dict(
@@ -1538,24 +1538,34 @@
 t((MultiTag,
+ CMultiTag
 ), dict(Mult
@@ -1604,16 +1604,21 @@
 ct((Tag,
+ CTag
 ), dict(

Patch both C++ and Python classes in EntityWithSources