/** * Create a new skill file based on argument path and mode. * * @throws IOException * on IO and mode related errors * @throws SkillException * on file or specification consistency errors * @note suppress unused warnings, because sometimes type declarations are * created, although nobody is using them */ public static new SkillFile open(string path, params Mode[] mode) { ActualMode actualMode = new ActualMode(mode); try { switch (actualMode.open) { case Mode.Create: // initialization order of type information has to match file // parser // and can not be done in place StringPool strings = new StringPool(null); List <AbstractStoragePool> types = new List <AbstractStoragePool>(1); StringType stringType = new StringType(strings); Annotation annotation = new Annotation(types); return(new SkillState(new Dictionary <string, AbstractStoragePool>(), strings, stringType, annotation, types, FileInputStream.open(path, false), actualMode.close)); case Mode.Read: Parser p = new Parser(FileInputStream.open(path, actualMode.close == Mode.ReadOnly)); return(p.read <SkillState>(typeof(SkillState), actualMode.close)); default: throw new System.InvalidOperationException("should never happen"); } } catch (SkillException e) { // rethrow all skill exceptions throw e; } catch (Exception e) { throw new SkillException(e); } }