+function uvlitem.type(self)
+ if self.t == TYPE_CONFIG then
+ return 'config'
+ elseif self.t == TYPE_SECTION then
+ return 'section'
+ elseif self.t == TYPE_OPTION then
+ return 'option'
+ elseif self.t == TYPE_ENUM then
+ return 'enum'
+ end
+end
+
+function uvlitem.error(self, ...)
+ if not self.e then
+ local errconst = { ERR.CONFIG, ERR.SECTION, ERR.OPTION, ERR.OPTION }
+ self.e = errconst[#self.cref]( self )
+ end
+
+ return self.e:child( ... )
+end
+
+function uvlitem.errors(self)
+ return self.e
+end
+
+function uvlitem.ok(self)
+ return not self:errors()
+end
+
+function uvlitem.parent(self)
+ if self.p then
+ return self.p
+ elseif #self.cref == 3 or #self.cref == 4 then
+ return section( self.s, self.c, self.cref[1], self.cref[2] )
+ elseif #self.cref == 2 then
+ return config( self.s, self.c, self.cref[1] )
+ else
+ return nil
+ end
+end
+
+function uvlitem._loadconf(self, co, c, configdir)
+ co = co or self._configcache
+ if not co then
+ local err
+ co, err = uci.cursor(configdir):get_all(c)
+
+ if err then
+ self:error(ERR.UCILOAD(self, err))
+ end
+
+ self._configcache = co
+ end
+ return co
+end
+
+
+--- Object representation of a scheme.
+-- @class scheme
+-- @cstyle instance
+-- @name luci.uvl.scheme
+
+--- Scheme instance constructor.
+-- @class function
+-- @name scheme
+-- @param scheme Scheme instance
+-- @param co Configuration data
+-- @param c Configuration name
+-- @return Config instance
+scheme = util.class(uvlitem)
+
+function scheme.__init__(self, scheme, co, c)
+ if not c then
+ c, co = co, nil
+ end
+
+ self.cref = { c }
+ self.sref = { c }
+ self.c = self:_loadconf(co, c, scheme.configdir)
+ self.s = scheme
+ self.t = TYPE_SCHEME
+end
+
+--- Add an error to scheme.
+-- @return Scheme error context
+function scheme.error(self, ...)
+ if not self.e then self.e = ERR.SCHEME( self ) end
+ return self.e:child( ... )
+end
+
+--- Get an associated config object.
+-- @return Config instance
+function scheme.config(self)
+ local co = config( self.s, self.cref[1] )
+ co.p = self
+
+ return co
+end
+
+--- Get all section objects associated with this scheme.
+-- @return Table containing all associated luci.uvl.section instances
+function scheme.sections(self)
+ local v = { }
+ if self.s.packages[self.sref[1]].sections then
+ for o, _ in pairs( self.s.packages[self.sref[1]].sections ) do
+ v[#v+1] = option(
+ self.s, self.c, self.cref[1], self.cref[2], o
+ )
+ end
+ end
+ return v
+end
+
+--- Get an associated section object.
+-- @param s Section to select
+-- @return Section instance
+function scheme.section(self, s)
+ local so = section( self.s, self.c, self.cref[1], s )
+ so.p = self
+
+ return so
+end
+
+
+--- Object representation of a config.
+-- @class config
+-- @cstyle instance
+-- @name luci.uvl.config
+
+--- Config instance constructor.
+-- @class function
+-- @name config
+-- @param scheme Scheme instance
+-- @param co Configuration data
+-- @param c Configuration name
+-- @return Config instance
+config = util.class(uvlitem)
+
+function config.__init__(self, scheme, co, c)
+ if not c then
+ c, co = co, nil
+ end
+ self.cref = { c }
+ self.sref = { c }
+ self.c = self:_loadconf(co, c, scheme.configdir)
+ self.s = scheme
+ self.t = TYPE_CONFIG
+end
+
+--- Get all section objects associated with this config.
+-- @return Table containing all associated luci.uvl.section instances
+function config.sections(self)
+ local v = { }
+ if self.s.packages[self.sref[1]].sections then
+ for o, _ in pairs( self.s.packages[self.sref[1]].sections ) do
+ v[#v+1] = option(
+ self.s, self.c, self.cref[1], self.cref[2], o
+ )
+ end
+ end
+ return v
+end
+
+--- Get an associated section object.
+-- @param s Section to select
+-- @return Section instance
+function config.section(self, s)
+ local so = section( self.s, self.c, self.cref[1], s )
+ so.p = self
+
+ return so
+end
+
+
+--- Object representation of a scheme/config section.
+-- @class module
+-- @cstyle instance
+-- @name luci.uvl.section
+
+--- Section instance constructor.
+-- @class function
+-- @name section
+-- @param scheme Scheme instance
+-- @param co Configuration data
+-- @param c Configuration name
+-- @param s Section name
+-- @return Section instance
+section = util.class(uvlitem)
+
+function section.__init__(self, scheme, co, c, s)
+ self.cref = { c, s }
+ self.sref = { c, co and co[s] and co[s]['.type'] or s }
+ self.c = self:_loadconf(co, c, scheme.configdir)
+ self.s = scheme
+ self.t = TYPE_SECTION
+end
+
+--- Get all option objects associated with this section.
+-- @return Table containing all associated luci.uvl.option instances