using System;
using System.IO;
using System.Text;
using System.Collections;
using Cobilas.IO.Atlf.Text;
using System.Collections.Generic;
namespace Cobilas.IO.Atlf {
/// Base class for ATLF read classes.
public abstract class ATLFReader : ATLFBase, IEnumerable {
/// Starts the process of reading the ATLF file.
public abstract void Reader();
/// Gets the ATLF header tags.
public abstract ATLFNode[] GetHeader();
/// Gets the value of the tag.
/// The name of the target tag.
public abstract string GetTag(string name);
/// Gets all comments from the ATLF file.
public abstract ATLFNode[] GetAllComments();
/// Gets a group of ATLF tags within a path.
/// Returns a list of ATLF tags according to a path.
/// Example: there are three nodes with the name com.cob.lib.tag1, com.cob.lib.tag2 and com.cob.cli.tag-1
/// and passing in the parameter com.cob.lib the tags tag1 and tag2 will be obtained.
public abstract ATLFNode[] GetTagGroup(string path);
/// Gets all nodes within the buffer.
public abstract IEnumerator GetEnumerator();
/// Gets the ATLF encoding.
/// The method returns the encoder corresponding to the version passed in the parameter.
/// If the previous version does not exist, the default version will be returned.
protected abstract ATLFDecoding GetATLFDecoding(string targetVersion);
#pragma warning disable CS1591
public static T Create(Stream stream) where T : ATLFSBReader => Create((MarshalByRefObject)stream);
public static T Create(string filePath) where T : ATLFSBReader => Create(File.OpenRead(filePath), true);
public static T Create(TextReader text) where T : ATLFTBReader => Create((MarshalByRefObject)text);
public static T Create(StringBuilder builder) where T : ATLFTBReader => Create(new StringReader(builder.ToString()), true);
public static ATLFReader Create(Stream stream) => Create(stream);
public static ATLFReader Create(string filePath) => Create(filePath);
public static ATLFReader Create(TextReader text) => Create(text);
public static ATLFReader Create(StringBuilder builder) => Create(builder);
#pragma warning restore
private static T Create(MarshalByRefObject refObject, bool closeFlow = false) where T : ATLFReader{
T reader = Activator.CreateInstance();
reader.RefObject = refObject;
reader.CloseFlow = closeFlow;
return reader;
}
IEnumerator IEnumerable.GetEnumerator()
=> (this as IEnumerable).GetEnumerator();
}
}