def _print_segment_path(fp, data_alias): path = ['"'] prefix = '' if fp.clazz.owner is not None: if isinstance(fp.clazz.owner, Package): prefix = '%s:' % fp.clazz.owner.stmt.arg elif fp.clazz.owner.stmt.i_module.arg != fp.clazz.stmt.i_module.arg: prefix = '%s:' % fp.clazz.stmt.i_module.arg path.append('%s%s"' % (prefix, fp.clazz.stmt.arg)) key_props = fp.clazz.get_key_props() if len(key_props) > 0: predicate = '"' for key_prop in key_props: key_name = '' if key_prop.stmt.i_module.arg != fp.clazz.stmt.i_module.arg: key_name += key_prop.stmt.i_module.arg key_name += ':' key_name += key_prop.stmt.arg path.append(" + types.AddKeyToken(%s.%s, \"%s\")" % (fp.class_alias, key_prop.go_name(), key_name)) elif is_list_element(fp.clazz): # list element with no keys path.append(" + types.AddNoKeyToken(%s)" % fp.class_alias) fp.ctx.writeln('%s.SegmentPath = %s' % (data_alias, ''.join(path)))
def _print_get_ydk_segment_path_body(self, clazz): self.ctx.writeln('std::ostringstream path_buffer;') path='"' if clazz.owner is not None: if isinstance(clazz.owner, Package): path+= clazz.owner.stmt.arg + ':' elif clazz.owner.stmt.i_module.arg != clazz.stmt.i_module.arg: path+=clazz.stmt.i_module.arg + ':' path+= clazz.stmt.arg + '";' self.ctx.writeln('path_buffer << %s' % (path)) key_props = clazz.get_key_props() if len(key_props) > 0: for key_prop in key_props: predicate = '' if key_prop.stmt.i_module.arg != clazz.stmt.i_module.arg: predicate += key_prop.stmt.i_module.arg predicate += ':' predicate += key_prop.stmt.arg self.ctx.writeln('ADD_KEY_TOKEN(%s, "%s");' % (key_prop.name, predicate)) elif is_list_element(clazz): # list element with no keys predicate = '"[" << get_ylist_key() << "]";' self.ctx.writeln('path_buffer << %s' % (predicate)) self.ctx.writeln('return path_buffer.str();')
def print_function_body(self): self.ctx.writeln('EntityData types.CommonEntityData') self.ctx.writeln('YFilter yfilter.YFilter') if is_list_element(self.clazz): self.ctx.writeln('YListKey string') if self.clazz.stmt.search_one('presence') is not None: self.ctx.writeln('YPresence bool') self._print_inits()
def _add_list_stmts(self, clazz): """Add list statements as well as its requisite statements.""" while not is_pkg_element(clazz): if all((is_list_element(clazz), not is_pkg_element(clazz.owner))): self._add_declaration_stmt(clazz) self._add_list_key_stmts(clazz) self._add_append_stmt(clazz) clazz = clazz.owner
def _add_requisite_clazz_stmts(self, clazz): """Add requisite statements for a YANG container.""" if is_presence_element(clazz): self._add_presence_clazz_stmts(clazz) if is_list_element(clazz): self._add_list_stmts(clazz)