Skip to content

Some minor changes #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
10 changes: 10 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
project(yavl-cpp)
cmake_minimum_required(VERSION 2.8)

find_package(PkgConfig REQUIRED)
pkg_check_modules (YAML REQUIRED yaml-cpp)

include_directories( include/yavl-cpp /usr/include/yaml-cpp )
link_libraries( yaml-cpp )

add_library(yavl-cpp SHARED src/yavl.cpp include/yavl-cpp/yavl.h)
73 changes: 73 additions & 0 deletions include/yavl-cpp/yavl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#ifndef _YAVL_H_
#define _YAVL_H_

#include "yaml-cpp/yaml.h"
#include <vector>
#include <string>
#include <ostream>

namespace YAVL {

typedef std::vector<std::string> Path;

// really sucks that I have to do this sort of crap since I can't
// pass a type as an argument to a function.
template<typename T>
std::string ctype2str() {
return "FAIL";
}

class Exception {
public:
std::string why;
Path gr_path;
Path doc_path;
Exception(const std::string _why, const Path& _gr_path,
const Path& _doc_path) :
why(_why), gr_path(_gr_path), doc_path(_doc_path) {
}
;
};

typedef std::vector<Exception> Errors;

class Validator {
const YAML::Node& gr;
const YAML::Node& doc;
Path gr_path;
Path doc_path;
Errors errors;

int num_keys(const YAML::Node& doc);
const std::string& type2str(const YAML::Node &doc);
bool validate_map(const YAML::Node &mapNode, const YAML::Node &doc);
bool validate_leaf(const YAML::Node &gr, const YAML::Node &doc);
bool validate_list(const YAML::Node &gr, const YAML::Node &doc);
bool validate_doc(const YAML::Node &gr, const YAML::Node &doc);

void gen_error(const Exception& err) {
errors.push_back(err);
}

public:
Validator(const YAML::Node& _gr, const YAML::Node& _doc) :
gr(_gr), doc(_doc) {
}
;

bool validate() {
return validate_doc(gr, doc);
}

const Errors& get_errors() {
return errors;
}
};
}

std::ostream& operator <<(std::ostream& os, const YAVL::Path& path);
std::ostream& operator <<(std::ostream& os, const YAVL::Exception& v);
std::ostream& operator <<(std::ostream& os, const YAVL::Errors& v);

#endif

29 changes: 29 additions & 0 deletions scripts/generate-pkgconfig.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash
#
# This script create a pkg-config file for this clone of yavl-cpp
# It's fixed to reference to the ../build as the build directory.
#
set -e

abspath=$(cd `dirname "${BASH_SOURCE[0]}"`/.. && pwd)
pkg_config_path="$1"

if [ -z ${pkg_config_path} ]; then
echo Please specify your pkgconfig directory
exit 1
fi

mkdir -p ${pkg_config_path}
cat > ${pkg_config_path}/yavl-cpp.pc <<EOF
Name: Yavl-cpp
Description: A YAML format validator for C++
Version: 0.5.1

prefix=$abspath
libdir=\${prefix}/build
includedir=\${prefix}/include

Requires: yaml-cpp >= 0.5.1
Libs: -L\${libdir} -lyavl-cpp
Cflags: -I\${includedir}
EOF
Loading