小编Azi*_*ias的帖子

json架构属性描述和"$ ref"用法

我正在编写一个json模式来验证由exe生成的json输出.模式有点复杂,我定义了一些在属性中引用的"定义"("$ ref":"#/ definitions/...)在这里使用定义更为重要,因为我有一个定义是递归的情况.

我的架构现在运行良好,它正确验证了我的json输出.

现在,我正在尝试使用每个属性的"description"关键字正确记录架构.为了开发模式,我使用了一个以图形方式表示模式的编辑器(XMLSpy).这是非常有用的,但我面对一个奇怪的行为,我不知道它是编辑器中的问题,还是我不理解.

这是一个json模式的最小例子来解释我的问题:

{
	"$schema": "http://json-schema.org/draft-04/schema#",
	"type": "object",
	"properties": {
		"sourcePath": {
			"$ref": "#/definitions/Path",
			"description": "Here the description where I expected to set it"
		},
		"targetPath": {
			"$ref": "#/definitions/Path",
			"description": "Here another description where I expected to set it to that property of the same kind but whith a different use."
		}
	},
	"additionalProperties": false,
	"definitions": {
		"Path": {
			"description": "Here the descriptiond where it is set by the software",
			"type": "object",
			"properties": {
				"aUsefulProperty": {
					"type": …
Run Code Online (Sandbox Code Playgroud)

json jsonschema json-schema-validator json-ref

9
推荐指数
2
解决办法
2687
查看次数

std :: hash专门用于我自己的类,并在类中使用它

我定义一个类Foo,并希望有一个以std::unordered_set<Foo>参数类型为参数的公共成员函数 。

为了能够使用std::unordered_set<Foo>,我必须专门std::hash<Foo> 研究std命名空间。

如果我不尝试std::unordered_set<Foo>Foo成员函数中用作参数类型,那没关系。

但是,一旦要std::unordered_set<Foo>Foo成员函数中用作参数类型,就很难定义专门化了 std::hash<Foo>。如果我在Foo声明后执行此操作,则声明时会出错,Foo因为std::hash<Foo>未定义。它std::hash<Foo>以前是一个移动定义,因为现在Foo未知,所以也不起作用。Foo在这种情况下,向前声明无效。

任何想法如何解决这个问题?

这是此类的示例

class Foo
{
public:
  std::unordered_set<Foo>::iterator findClosest(std::unordered_set<Foo> const &others)
  {
    return std::end(others);
  }

  size_t hashValue() const {
    return std::hash<int>()(m_Member);
  }

private:
  int m_Member;
};

namespace std
{
  template <>
  struct hash<Foo>
  {
    size_t operator()(Foo const & bar) const
    {
      return bar.hashValue();
    }
  };
} …
Run Code Online (Sandbox Code Playgroud)

c++ c++11

5
推荐指数
1
解决办法
160
查看次数

标签 统计

c++ ×1

c++11 ×1

json ×1

json-ref ×1

json-schema-validator ×1

jsonschema ×1