<commit_before>/*
 *  yosys -- Yosys Open SYnthesis Suite
 *
 *  Copyright (C) 2012  Clifford Wolf <clifford@clifford.at>
 *
 *  Permission to use, copy, modify, and/or distribute this software for any
 *  purpose with or without fee is hereby granted, provided that the above
 *  copyright notice and this permission notice appear in all copies.
 *
 *  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 *  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 *  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 *  ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 *  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 *  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 *  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 *
 */

#include "blifparse.h"

YOSYS_NAMESPACE_BEGIN

static bool read_next_line(char *&buffer, size_t &buffer_size, int &line_count, FILE *f)
{
	int buffer_len = 0;
	buffer[0] = 0;

	while (1)
	{
		buffer_len += strlen(buffer + buffer_len);
		while (buffer_len > 0 && (buffer[buffer_len-1] == ' ' || buffer[buffer_len-1] == '\t' ||
				buffer[buffer_len-1] == '\r' || buffer[buffer_len-1] == '\n'))
			buffer[--buffer_len] = 0;

		if (buffer_size-buffer_len < 4096) {
			buffer_size *= 2;
			buffer = (char*)realloc(buffer, buffer_size);
		}

		if (buffer_len == 0 || buffer[buffer_len-1] == '\\') {
			if (buffer_len > 0 && buffer[buffer_len-1] == '\\')
				buffer[--buffer_len] = 0;
			line_count++;
			if (fgets(buffer+buffer_len, buffer_size-buffer_len, f) == NULL)
				return false;
		} else
			return true;
	}
}

RTLIL::Design *abc_parse_blif(FILE *f, std::string dff_name)
{
	RTLIL::Design *design = new RTLIL::Design;
	RTLIL::Module *module = new RTLIL::Module;

	RTLIL::Const *lutptr = NULL;
	RTLIL::State lut_default_state = RTLIL::State::Sx;

	module->name = "\\netlist";
	design->add(module);

	size_t buffer_size = 4096;
	char *buffer = (char*)malloc(buffer_size);
	int line_count = 0;

	while (1)
	{
		if (!read_next_line(buffer, buffer_size, line_count, f))
			goto error;

	continue_without_read:
		if (buffer[0] == '#')
			continue;

		if (buffer[0] == '.')
		{
			if (lutptr) {
				for (auto &bit : lutptr->bits)
					if (bit == RTLIL::State::Sx)
						bit = lut_default_state;
				lutptr = NULL;
				lut_default_state = RTLIL::State::Sx;
			}

			char *cmd = strtok(buffer, " \t\r\n");

			if (!strcmp(cmd, ".model"))
				continue;

			if (!strcmp(cmd, ".end")) {
				module->fixup_ports();
				free(buffer);
				return design;
			}

			if (!strcmp(cmd, ".inputs") || !strcmp(cmd, ".outputs")) {
				char *p;
				while ((p = strtok(NULL, " \t\r\n")) != NULL) {
					RTLIL::Wire *wire = module->addWire(stringf("\\%s", p));
					if (!strcmp(cmd, ".inputs"))
						wire->port_input = true;
					else
						wire->port_output = true;
				}
				continue;
			}

			if (!strcmp(cmd, ".latch"))
			{
				char *d = strtok(NULL, " \t\r\n");
				char *q = strtok(NULL, " \t\r\n");

				if (module->wires_.count(RTLIL::escape_id(d)) == 0)
					module->addWire(RTLIL::escape_id(d));

				if (module->wires_.count(RTLIL::escape_id(q)) == 0)
					module->addWire(RTLIL::escape_id(q));

				RTLIL::Cell *cell = module->addCell(NEW_ID, dff_name);
				cell->setPort("\\D", module->wires_.at(RTLIL::escape_id(d)));
				cell->setPort("\\Q", module->wires_.at(RTLIL::escape_id(q)));
				continue;
			}

			if (!strcmp(cmd, ".gate"))
			{
				char *p = strtok(NULL, " \t\r\n");
				if (p == NULL)
					goto error;

				IdString celltype = RTLIL::escape_id(p);
				RTLIL::Cell *cell = module->addCell(NEW_ID, celltype);

				while ((p = strtok(NULL, " \t\r\n")) != NULL) {
					char *q = strchr(p, '=');
					if (q == NULL || !q[0] || !q[1])
						goto error;
					*(q++) = 0;
					if (module->wires_.count(RTLIL::escape_id(q)) == 0)
						module->addWire(RTLIL::escape_id(q));
					cell->setPort(RTLIL::escape_id(p), module->wires_.at(RTLIL::escape_id(q)));
				}
				continue;
			}

			if (!strcmp(cmd, ".names"))
			{
				char *p;
				RTLIL::SigSpec input_sig, output_sig;
				while ((p = strtok(NULL, " \t\r\n")) != NULL) {
					RTLIL::Wire *wire;
					if (module->wires_.count(stringf("\\%s", p)) > 0) {
						wire = module->wires_.at(stringf("\\%s", p));
					} else {
						wire = module->addWire(stringf("\\%s", p));
					}
					input_sig.append(wire);
				}
				output_sig = input_sig.extract(input_sig.size()-1, 1);
				input_sig = input_sig.extract(0, input_sig.size()-1);

				if (input_sig.size() == 0) {
					RTLIL::State state = RTLIL::State::Sa;
					while (1) {
						if (!read_next_line(buffer, buffer_size, line_count, f))
							goto error;
						for (int i = 0; buffer[i]; i++) {
							if (buffer[i] == ' ' || buffer[i] == '\t')
								continue;
							if (i == 0 && buffer[i] == '.')
								goto finished_parsing_constval;
							if (buffer[i] == '0') {
								if (state == RTLIL::State::S1)
									goto error;
								state = RTLIL::State::S0;
								continue;
							}
							if (buffer[i] == '1') {
								if (state == RTLIL::State::S0)
									goto error;
								state = RTLIL::State::S1;
								continue;
							}
							goto error;
						}
					}
				finished_parsing_constval:
					if (state == RTLIL::State::Sa)
						state = RTLIL::State::S1;
					module->connect(RTLIL::SigSig(output_sig, state));
					goto continue_without_read;
				}

				RTLIL::Cell *cell = module->addCell(NEW_ID, "$lut");
				cell->parameters["\\WIDTH"] = RTLIL::Const(input_sig.size());
				cell->parameters["\\LUT"] = RTLIL::Const(RTLIL::State::Sx, 1 << input_sig.size());
				cell->setPort("\\A", input_sig);
				cell->setPort("\\Y", output_sig);
				lutptr = &cell->parameters.at("\\LUT");
				lut_default_state = RTLIL::State::Sx;
				continue;
			}

			goto error;
		}

		if (lutptr == NULL)
			goto error;

		char *input = strtok(buffer, " \t\r\n");
		char *output = strtok(NULL, " \t\r\n");

		if (input == NULL || output == NULL || (strcmp(output, "0") && strcmp(output, "1")))
			goto error;

		int input_len = strlen(input);
		if (input_len > 8)
			goto error;

		for (int i = 0; i < (1 << input_len); i++) {
			for (int j = 0; j < input_len; j++) {
				char c1 = input[j];
				if (c1 != '-') {
					char c2 = (i & (1 << j)) != 0 ? '1' : '0';
					if (c1 != c2)
						goto try_next_value;
				}
			}
			lutptr->bits.at(i) = !strcmp(output, "0") ? RTLIL::State::S0 : RTLIL::State::S1;
		try_next_value:;
		}

		lut_default_state = !strcmp(output, "0") ? RTLIL::State::S1 : RTLIL::State::S0;
	}

error:
	log_error("Syntax error in line %d!\n", line_count);
	// delete design;
	// return NULL;
}

YOSYS_NAMESPACE_END

<commit_msg>Added .barbuf support to abc BLIF parser<commit_after>/*
 *  yosys -- Yosys Open SYnthesis Suite
 *
 *  Copyright (C) 2012  Clifford Wolf <clifford@clifford.at>
 *
 *  Permission to use, copy, modify, and/or distribute this software for any
 *  purpose with or without fee is hereby granted, provided that the above
 *  copyright notice and this permission notice appear in all copies.
 *
 *  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 *  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 *  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 *  ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 *  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 *  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 *  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 *
 */

#include "blifparse.h"

YOSYS_NAMESPACE_BEGIN

static bool read_next_line(char *&buffer, size_t &buffer_size, int &line_count, FILE *f)
{
	int buffer_len = 0;
	buffer[0] = 0;

	while (1)
	{
		buffer_len += strlen(buffer + buffer_len);
		while (buffer_len > 0 && (buffer[buffer_len-1] == ' ' || buffer[buffer_len-1] == '\t' ||
				buffer[buffer_len-1] == '\r' || buffer[buffer_len-1] == '\n'))
			buffer[--buffer_len] = 0;

		if (buffer_size-buffer_len < 4096) {
			buffer_size *= 2;
			buffer = (char*)realloc(buffer, buffer_size);
		}

		if (buffer_len == 0 || buffer[buffer_len-1] == '\\') {
			if (buffer_len > 0 && buffer[buffer_len-1] == '\\')
				buffer[--buffer_len] = 0;
			line_count++;
			if (fgets(buffer+buffer_len, buffer_size-buffer_len, f) == NULL)
				return false;
		} else
			return true;
	}
}

RTLIL::Design *abc_parse_blif(FILE *f, std::string dff_name)
{
	RTLIL::Design *design = new RTLIL::Design;
	RTLIL::Module *module = new RTLIL::Module;

	RTLIL::Const *lutptr = NULL;
	RTLIL::State lut_default_state = RTLIL::State::Sx;

	module->name = "\\netlist";
	design->add(module);

	size_t buffer_size = 4096;
	char *buffer = (char*)malloc(buffer_size);
	int line_count = 0;

	while (1)
	{
		if (!read_next_line(buffer, buffer_size, line_count, f))
			goto error;

	continue_without_read:
		if (buffer[0] == '#')
			continue;

		if (buffer[0] == '.')
		{
			if (lutptr) {
				for (auto &bit : lutptr->bits)
					if (bit == RTLIL::State::Sx)
						bit = lut_default_state;
				lutptr = NULL;
				lut_default_state = RTLIL::State::Sx;
			}

			char *cmd = strtok(buffer, " \t\r\n");

			if (!strcmp(cmd, ".model"))
				continue;

			if (!strcmp(cmd, ".end")) {
				module->fixup_ports();
				free(buffer);
				return design;
			}

			if (!strcmp(cmd, ".inputs") || !strcmp(cmd, ".outputs")) {
				char *p;
				while ((p = strtok(NULL, " \t\r\n")) != NULL) {
					RTLIL::Wire *wire = module->addWire(stringf("\\%s", p));
					if (!strcmp(cmd, ".inputs"))
						wire->port_input = true;
					else
						wire->port_output = true;
				}
				continue;
			}

			if (!strcmp(cmd, ".latch"))
			{
				char *d = strtok(NULL, " \t\r\n");
				char *q = strtok(NULL, " \t\r\n");

				if (module->wires_.count(RTLIL::escape_id(d)) == 0)
					module->addWire(RTLIL::escape_id(d));

				if (module->wires_.count(RTLIL::escape_id(q)) == 0)
					module->addWire(RTLIL::escape_id(q));

				RTLIL::Cell *cell = module->addCell(NEW_ID, dff_name);
				cell->setPort("\\D", module->wires_.at(RTLIL::escape_id(d)));
				cell->setPort("\\Q", module->wires_.at(RTLIL::escape_id(q)));
				continue;
			}

			if (!strcmp(cmd, ".gate"))
			{
				char *p = strtok(NULL, " \t\r\n");
				if (p == NULL)
					goto error;

				IdString celltype = RTLIL::escape_id(p);
				RTLIL::Cell *cell = module->addCell(NEW_ID, celltype);

				while ((p = strtok(NULL, " \t\r\n")) != NULL) {
					char *q = strchr(p, '=');
					if (q == NULL || !q[0] || !q[1])
						goto error;
					*(q++) = 0;
					if (module->wires_.count(RTLIL::escape_id(q)) == 0)
						module->addWire(RTLIL::escape_id(q));
					cell->setPort(RTLIL::escape_id(p), module->wires_.at(RTLIL::escape_id(q)));
				}
				continue;
			}

			if (!strcmp(cmd, ".barbuf"))
			{
				char *p = strtok(NULL, " \t\r\n");
				if (p == NULL)
					goto error;

				char *q = strtok(NULL, " \t\r\n");
				if (q == NULL)
					goto error;

				if (module->wires_.count(RTLIL::escape_id(p)) == 0)
					module->addWire(RTLIL::escape_id(p));

				if (module->wires_.count(RTLIL::escape_id(q)) == 0)
					module->addWire(RTLIL::escape_id(q));

				module->connect(module->wires_.at(RTLIL::escape_id(q)), module->wires_.at(RTLIL::escape_id(p)));
				continue;
			}

			if (!strcmp(cmd, ".names"))
			{
				char *p;
				RTLIL::SigSpec input_sig, output_sig;
				while ((p = strtok(NULL, " \t\r\n")) != NULL) {
					RTLIL::Wire *wire;
					if (module->wires_.count(stringf("\\%s", p)) > 0) {
						wire = module->wires_.at(stringf("\\%s", p));
					} else {
						wire = module->addWire(stringf("\\%s", p));
					}
					input_sig.append(wire);
				}
				output_sig = input_sig.extract(input_sig.size()-1, 1);
				input_sig = input_sig.extract(0, input_sig.size()-1);

				if (input_sig.size() == 0) {
					RTLIL::State state = RTLIL::State::Sa;
					while (1) {
						if (!read_next_line(buffer, buffer_size, line_count, f))
							goto error;
						for (int i = 0; buffer[i]; i++) {
							if (buffer[i] == ' ' || buffer[i] == '\t')
								continue;
							if (i == 0 && buffer[i] == '.')
								goto finished_parsing_constval;
							if (buffer[i] == '0') {
								if (state == RTLIL::State::S1)
									goto error;
								state = RTLIL::State::S0;
								continue;
							}
							if (buffer[i] == '1') {
								if (state == RTLIL::State::S0)
									goto error;
								state = RTLIL::State::S1;
								continue;
							}
							goto error;
						}
					}
				finished_parsing_constval:
					if (state == RTLIL::State::Sa)
						state = RTLIL::State::S1;
					module->connect(RTLIL::SigSig(output_sig, state));
					goto continue_without_read;
				}

				RTLIL::Cell *cell = module->addCell(NEW_ID, "$lut");
				cell->parameters["\\WIDTH"] = RTLIL::Const(input_sig.size());
				cell->parameters["\\LUT"] = RTLIL::Const(RTLIL::State::Sx, 1 << input_sig.size());
				cell->setPort("\\A", input_sig);
				cell->setPort("\\Y", output_sig);
				lutptr = &cell->parameters.at("\\LUT");
				lut_default_state = RTLIL::State::Sx;
				continue;
			}

			goto error;
		}

		if (lutptr == NULL)
			goto error;

		char *input = strtok(buffer, " \t\r\n");
		char *output = strtok(NULL, " \t\r\n");

		if (input == NULL || output == NULL || (strcmp(output, "0") && strcmp(output, "1")))
			goto error;

		int input_len = strlen(input);
		if (input_len > 8)
			goto error;

		for (int i = 0; i < (1 << input_len); i++) {
			for (int j = 0; j < input_len; j++) {
				char c1 = input[j];
				if (c1 != '-') {
					char c2 = (i & (1 << j)) != 0 ? '1' : '0';
					if (c1 != c2)
						goto try_next_value;
				}
			}
			lutptr->bits.at(i) = !strcmp(output, "0") ? RTLIL::State::S0 : RTLIL::State::S1;
		try_next_value:;
		}

		lut_default_state = !strcmp(output, "0") ? RTLIL::State::S1 : RTLIL::State::S0;
	}

error:
	log_error("Syntax error in line %d!\n", line_count);
	// delete design;
	// return NULL;
}

YOSYS_NAMESPACE_END

<|endoftext|>


<commit_before>//===- FastISelEmitter.cpp - Generate an instruction selector -------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This tablegen backend emits a "fast" instruction selector.
//
// This instruction selection method is designed to emit very poor code
// quickly. Also, it is not designed to do much lowering, so most illegal
// types (e.g. i64 on 32-bit targets) and operations (e.g. calls) are not
// supported and cannot easily be added. Blocks containing operations
// that are not supported need to be handled by a more capable selector,
// such as the SelectionDAG selector.
//
// The intended use for "fast" instruction selection is "-O0" mode
// compilation, where the quality of the generated code is irrelevant when
// weighed against the speed at which the code can be generated.
//
// If compile time is so important, you might wonder why we don't just
// skip codegen all-together, emit LLVM bytecode files, and execute them
// with an interpreter. The answer is that it would complicate linking and
// debugging, and also because that isn't how a compiler is expected to
// work in some circles.
//
// If you need better generated code or more lowering than what this
// instruction selector provides, use the SelectionDAG (DAGISel) instruction
// selector instead. If you're looking here because SelectionDAG isn't fast
// enough, consider looking into improving the SelectionDAG infastructure
// instead. At the time of this writing there remain several major
// opportunities for improvement.
//
//===----------------------------------------------------------------------===//

#include "FastISelEmitter.h"
#include "Record.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/Streams.h"
#include "llvm/ADT/VectorExtras.h"
using namespace llvm;

namespace {

/// OperandsSignature - This class holds a description of a list of operand
/// types. It has utility methods for emitting text based on the operands.
///
struct OperandsSignature {
  std::vector<std::string> Operands;

  bool operator<(const OperandsSignature &O) const {
    return Operands < O.Operands;
  }

  bool empty() const { return Operands.empty(); }

  void PrintParameters(std::ostream &OS) const {
    for (unsigned i = 0, e = Operands.size(); i != e; ++i) {
      if (Operands[i] == "r") {
        OS << "unsigned Op" << i;
      } else {
        assert("Unknown operand kind!");
        abort();
      }
      if (i + 1 != e)
        OS << ", ";
    }
  }

  void PrintArguments(std::ostream &OS) const {
    for (unsigned i = 0, e = Operands.size(); i != e; ++i) {
      if (Operands[i] == "r") {
        OS << "Op" << i;
      } else {
        assert("Unknown operand kind!");
        abort();
      }
      if (i + 1 != e)
        OS << ", ";
    }
  }

  void PrintManglingSuffix(std::ostream &OS) const {
    for (unsigned i = 0, e = Operands.size(); i != e; ++i) {
      OS << Operands[i];
    }
  }
};

/// InstructionMemo - This class holds additional information about an
/// instruction needed to emit code for it.
///
struct InstructionMemo {
  std::string Name;
  const CodeGenRegisterClass *RC;
};

}

static std::string getOpcodeName(Record *Op, CodeGenDAGPatterns &CGP) {
  return CGP.getSDNodeInfo(Op).getEnumName();
}

static std::string getLegalCName(std::string OpName) {
  std::string::size_type pos = OpName.find("::");
  if (pos != std::string::npos)
    OpName.replace(pos, 2, "_");
  return OpName;
}

void FastISelEmitter::run(std::ostream &OS) {
  EmitSourceFileHeader("\"Fast\" Instruction Selector for the " +
                       CGP.getTargetInfo().getName() + " target", OS);

  const CodeGenTarget &Target = CGP.getTargetInfo();

  // Get the namespace to insert instructions into.  Make sure not to pick up
  // "TargetInstrInfo" by accidentally getting the namespace off the PHI
  // instruction or something.
  std::string InstNS;
  for (CodeGenTarget::inst_iterator i = Target.inst_begin(),
       e = Target.inst_end(); i != e; ++i) {
    InstNS = i->second.Namespace;
    if (InstNS != "TargetInstrInfo")
      break;
  }

  OS << "namespace llvm {\n";
  OS << "namespace " << InstNS << " {\n";
  OS << "class FastISel;\n";
  OS << "}\n";
  OS << "}\n";
  OS << "\n";

  if (!InstNS.empty()) InstNS += "::";

  typedef std::map<MVT::SimpleValueType, InstructionMemo> TypeMap;
  typedef std::map<std::string, TypeMap> OpcodeTypeMap;
  typedef std::map<OperandsSignature, OpcodeTypeMap> OperandsOpcodeTypeMap;
  OperandsOpcodeTypeMap SimplePatterns;

  // Create the supported type signatures.
  OperandsSignature KnownOperands;
  SimplePatterns[KnownOperands] = OpcodeTypeMap();
  KnownOperands.Operands.push_back("r");
  SimplePatterns[KnownOperands] = OpcodeTypeMap();
  KnownOperands.Operands.push_back("r");
  SimplePatterns[KnownOperands] = OpcodeTypeMap();

  for (CodeGenDAGPatterns::ptm_iterator I = CGP.ptm_begin(),
       E = CGP.ptm_end(); I != E; ++I) {
    const PatternToMatch &Pattern = *I;

    // For now, just look at Instructions, so that we don't have to worry
    // about emitting multiple instructions for a pattern.
    TreePatternNode *Dst = Pattern.getDstPattern();
    if (Dst->isLeaf()) continue;
    Record *Op = Dst->getOperator();
    if (!Op->isSubClassOf("Instruction"))
      continue;
    CodeGenInstruction &II = CGP.getTargetInfo().getInstruction(Op->getName());
    if (II.OperandList.empty())
      continue;
    Record *Op0Rec = II.OperandList[0].Rec;
    if (!Op0Rec->isSubClassOf("RegisterClass"))
      continue;
    const CodeGenRegisterClass *DstRC = &Target.getRegisterClass(Op0Rec);
    if (!DstRC)
      continue;

    // Inspect the pattern.
    TreePatternNode *InstPatNode = Pattern.getSrcPattern();
    if (!InstPatNode) continue;
    if (InstPatNode->isLeaf()) continue;

    Record *InstPatOp = InstPatNode->getOperator();
    std::string OpcodeName = getOpcodeName(InstPatOp, CGP);
    MVT::SimpleValueType VT = InstPatNode->getTypeNum(0);

    // For now, filter out instructions which just set a register to
    // an Operand, like MOV32ri.
    if (InstPatOp->isSubClassOf("Operand"))
      continue;

    // Check all the operands. For now only accept register operands.
    OperandsSignature Operands;
    for (unsigned i = 0, e = InstPatNode->getNumChildren(); i != e; ++i) {
      TreePatternNode *Op = InstPatNode->getChild(i);
      if (!Op->isLeaf())
        goto continue_label;
      DefInit *OpDI = dynamic_cast<DefInit*>(Op->getLeafValue());
      if (!OpDI)
        goto continue_label;
      Record *OpLeafRec = OpDI->getDef();
      if (!OpLeafRec->isSubClassOf("RegisterClass"))
        goto continue_label;
      const CodeGenRegisterClass *RC = &Target.getRegisterClass(OpLeafRec);
      if (!RC)
        goto continue_label;
      if (Op->getTypeNum(0) != VT)
        goto continue_label;
      Operands.Operands.push_back("r");
    }

    // If it's not a known signature, ignore it.
    if (!SimplePatterns.count(Operands))
      continue;

    // Ok, we found a pattern that we can handle. Remember it.
    {
      InstructionMemo Memo = { Pattern.getDstPattern()->getOperator()->getName(),
                               DstRC };
      SimplePatterns[Operands][OpcodeName][VT] = Memo;
    }

  continue_label:;
  }

  OS << "#include \"llvm/CodeGen/FastISel.h\"\n";
  OS << "\n";
  OS << "namespace llvm {\n";
  OS << "\n";

  // Declare the target FastISel class.
  OS << "class " << InstNS << "FastISel : public llvm::FastISel {\n";
  for (OperandsOpcodeTypeMap::const_iterator OI = SimplePatterns.begin(),
       OE = SimplePatterns.end(); OI != OE; ++OI) {
    const OperandsSignature &Operands = OI->first;
    const OpcodeTypeMap &OTM = OI->second;

    for (OpcodeTypeMap::const_iterator I = OTM.begin(), E = OTM.end();
         I != E; ++I) {
      const std::string &Opcode = I->first;
      const TypeMap &TM = I->second;

      for (TypeMap::const_iterator TI = TM.begin(), TE = TM.end();
           TI != TE; ++TI) {
        MVT::SimpleValueType VT = TI->first;

        OS << "  unsigned FastEmit_" << getLegalCName(Opcode)
           << "_" << getLegalCName(getName(VT)) << "(";
        Operands.PrintParameters(OS);
        OS << ");\n";
      }

      OS << "  unsigned FastEmit_" << getLegalCName(Opcode)
         << "(MVT::SimpleValueType VT";
      if (!Operands.empty())
        OS << ", ";
      Operands.PrintParameters(OS);
      OS << ");\n";
    }

    OS << "unsigned FastEmit_";
    Operands.PrintManglingSuffix(OS);
    OS << "(MVT::SimpleValueType VT, ISD::NodeType Opcode";
    if (!Operands.empty())
      OS << ", ";
    Operands.PrintParameters(OS);
    OS << ");\n";
  }
  OS << "public:\n";
  OS << "  FastISel(MachineBasicBlock *mbb, MachineFunction *mf, ";
  OS << "const TargetInstrInfo *tii) : llvm::FastISel(mbb, mf, tii) {}\n";
  OS << "};\n";
  OS << "\n";

  // Define the target FastISel creation function.
  OS << "llvm::FastISel *" << InstNS
     << "createFastISel(MachineBasicBlock *mbb, MachineFunction *mf, ";
  OS << "const TargetInstrInfo *tii) {\n";
  OS << "  return new " << InstNS << "FastISel(mbb, mf, tii);\n";
  OS << "}\n";
  OS << "\n";

  // Now emit code for all the patterns that we collected.
  for (OperandsOpcodeTypeMap::const_iterator OI = SimplePatterns.begin(),
       OE = SimplePatterns.end(); OI != OE; ++OI) {
    const OperandsSignature &Operands = OI->first;
    const OpcodeTypeMap &OTM = OI->second;

    for (OpcodeTypeMap::const_iterator I = OTM.begin(), E = OTM.end();
         I != E; ++I) {
      const std::string &Opcode = I->first;
      const TypeMap &TM = I->second;

      OS << "// FastEmit functions for " << Opcode << ".\n";
      OS << "\n";

      // Emit one function for each opcode,type pair.
      for (TypeMap::const_iterator TI = TM.begin(), TE = TM.end();
           TI != TE; ++TI) {
        MVT::SimpleValueType VT = TI->first;
        const InstructionMemo &Memo = TI->second;

        OS << "unsigned " << InstNS << "FastISel::FastEmit_"
           << getLegalCName(Opcode)
           << "_" << getLegalCName(getName(VT)) << "(";
        Operands.PrintParameters(OS);
        OS << ") {\n";
        OS << "  return FastEmitInst_";
        Operands.PrintManglingSuffix(OS);
        OS << "(" << InstNS << Memo.Name << ", ";
        OS << InstNS << Memo.RC->getName() << "RegisterClass";
        if (!Operands.empty())
          OS << ", ";
        Operands.PrintArguments(OS);
        OS << ");\n";
        OS << "}\n";
        OS << "\n";
      }

      // Emit one function for the opcode that demultiplexes based on the type.
      OS << "unsigned " << InstNS << "FastISel::FastEmit_"
         << getLegalCName(Opcode) << "(MVT::SimpleValueType VT";
      if (!Operands.empty())
        OS << ", ";
      Operands.PrintParameters(OS);
      OS << ") {\n";
      OS << "  switch (VT) {\n";
      for (TypeMap::const_iterator TI = TM.begin(), TE = TM.end();
           TI != TE; ++TI) {
        MVT::SimpleValueType VT = TI->first;
        std::string TypeName = getName(VT);
        OS << "  case " << TypeName << ": return FastEmit_"
           << getLegalCName(Opcode) << "_" << getLegalCName(TypeName) << "(";
        Operands.PrintArguments(OS);
        OS << ");\n";
      }
      OS << "  default: return 0;\n";
      OS << "  }\n";
      OS << "}\n";
      OS << "\n";
    }

    // Emit one function for the operand signature that demultiplexes based
    // on opcode and type.
    OS << "unsigned " << InstNS << "FastISel::FastEmit_";
    Operands.PrintManglingSuffix(OS);
    OS << "(MVT::SimpleValueType VT, ISD::NodeType Opcode";
    if (!Operands.empty())
      OS << ", ";
    Operands.PrintParameters(OS);
    OS << ") {\n";
    OS << "  switch (Opcode) {\n";
    for (OpcodeTypeMap::const_iterator I = OTM.begin(), E = OTM.end();
         I != E; ++I) {
      const std::string &Opcode = I->first;

      OS << "  case " << Opcode << ": return FastEmit_"
         << getLegalCName(Opcode) << "(VT";
      if (!Operands.empty())
        OS << ", ";
      Operands.PrintArguments(OS);
      OS << ");\n";
    }
    OS << "  default: return 0;\n";
    OS << "  }\n";
    OS << "}\n";
    OS << "\n";
  }

  OS << "}\n";
}

// todo: really filter out Constants
<commit_msg>80 columns.<commit_after>//===- FastISelEmitter.cpp - Generate an instruction selector -------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This tablegen backend emits a "fast" instruction selector.
//
// This instruction selection method is designed to emit very poor code
// quickly. Also, it is not designed to do much lowering, so most illegal
// types (e.g. i64 on 32-bit targets) and operations (e.g. calls) are not
// supported and cannot easily be added. Blocks containing operations
// that are not supported need to be handled by a more capable selector,
// such as the SelectionDAG selector.
//
// The intended use for "fast" instruction selection is "-O0" mode
// compilation, where the quality of the generated code is irrelevant when
// weighed against the speed at which the code can be generated.
//
// If compile time is so important, you might wonder why we don't just
// skip codegen all-together, emit LLVM bytecode files, and execute them
// with an interpreter. The answer is that it would complicate linking and
// debugging, and also because that isn't how a compiler is expected to
// work in some circles.
//
// If you need better generated code or more lowering than what this
// instruction selector provides, use the SelectionDAG (DAGISel) instruction
// selector instead. If you're looking here because SelectionDAG isn't fast
// enough, consider looking into improving the SelectionDAG infastructure
// instead. At the time of this writing there remain several major
// opportunities for improvement.
//
//===----------------------------------------------------------------------===//

#include "FastISelEmitter.h"
#include "Record.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/Streams.h"
#include "llvm/ADT/VectorExtras.h"
using namespace llvm;

namespace {

/// OperandsSignature - This class holds a description of a list of operand
/// types. It has utility methods for emitting text based on the operands.
///
struct OperandsSignature {
  std::vector<std::string> Operands;

  bool operator<(const OperandsSignature &O) const {
    return Operands < O.Operands;
  }

  bool empty() const { return Operands.empty(); }

  void PrintParameters(std::ostream &OS) const {
    for (unsigned i = 0, e = Operands.size(); i != e; ++i) {
      if (Operands[i] == "r") {
        OS << "unsigned Op" << i;
      } else {
        assert("Unknown operand kind!");
        abort();
      }
      if (i + 1 != e)
        OS << ", ";
    }
  }

  void PrintArguments(std::ostream &OS) const {
    for (unsigned i = 0, e = Operands.size(); i != e; ++i) {
      if (Operands[i] == "r") {
        OS << "Op" << i;
      } else {
        assert("Unknown operand kind!");
        abort();
      }
      if (i + 1 != e)
        OS << ", ";
    }
  }

  void PrintManglingSuffix(std::ostream &OS) const {
    for (unsigned i = 0, e = Operands.size(); i != e; ++i) {
      OS << Operands[i];
    }
  }
};

/// InstructionMemo - This class holds additional information about an
/// instruction needed to emit code for it.
///
struct InstructionMemo {
  std::string Name;
  const CodeGenRegisterClass *RC;
};

}

static std::string getOpcodeName(Record *Op, CodeGenDAGPatterns &CGP) {
  return CGP.getSDNodeInfo(Op).getEnumName();
}

static std::string getLegalCName(std::string OpName) {
  std::string::size_type pos = OpName.find("::");
  if (pos != std::string::npos)
    OpName.replace(pos, 2, "_");
  return OpName;
}

void FastISelEmitter::run(std::ostream &OS) {
  EmitSourceFileHeader("\"Fast\" Instruction Selector for the " +
                       CGP.getTargetInfo().getName() + " target", OS);

  const CodeGenTarget &Target = CGP.getTargetInfo();

  // Get the namespace to insert instructions into.  Make sure not to pick up
  // "TargetInstrInfo" by accidentally getting the namespace off the PHI
  // instruction or something.
  std::string InstNS;
  for (CodeGenTarget::inst_iterator i = Target.inst_begin(),
       e = Target.inst_end(); i != e; ++i) {
    InstNS = i->second.Namespace;
    if (InstNS != "TargetInstrInfo")
      break;
  }

  OS << "namespace llvm {\n";
  OS << "namespace " << InstNS << " {\n";
  OS << "class FastISel;\n";
  OS << "}\n";
  OS << "}\n";
  OS << "\n";

  if (!InstNS.empty()) InstNS += "::";

  typedef std::map<MVT::SimpleValueType, InstructionMemo> TypeMap;
  typedef std::map<std::string, TypeMap> OpcodeTypeMap;
  typedef std::map<OperandsSignature, OpcodeTypeMap> OperandsOpcodeTypeMap;
  OperandsOpcodeTypeMap SimplePatterns;

  // Create the supported type signatures.
  OperandsSignature KnownOperands;
  SimplePatterns[KnownOperands] = OpcodeTypeMap();
  KnownOperands.Operands.push_back("r");
  SimplePatterns[KnownOperands] = OpcodeTypeMap();
  KnownOperands.Operands.push_back("r");
  SimplePatterns[KnownOperands] = OpcodeTypeMap();

  for (CodeGenDAGPatterns::ptm_iterator I = CGP.ptm_begin(),
       E = CGP.ptm_end(); I != E; ++I) {
    const PatternToMatch &Pattern = *I;

    // For now, just look at Instructions, so that we don't have to worry
    // about emitting multiple instructions for a pattern.
    TreePatternNode *Dst = Pattern.getDstPattern();
    if (Dst->isLeaf()) continue;
    Record *Op = Dst->getOperator();
    if (!Op->isSubClassOf("Instruction"))
      continue;
    CodeGenInstruction &II = CGP.getTargetInfo().getInstruction(Op->getName());
    if (II.OperandList.empty())
      continue;
    Record *Op0Rec = II.OperandList[0].Rec;
    if (!Op0Rec->isSubClassOf("RegisterClass"))
      continue;
    const CodeGenRegisterClass *DstRC = &Target.getRegisterClass(Op0Rec);
    if (!DstRC)
      continue;

    // Inspect the pattern.
    TreePatternNode *InstPatNode = Pattern.getSrcPattern();
    if (!InstPatNode) continue;
    if (InstPatNode->isLeaf()) continue;

    Record *InstPatOp = InstPatNode->getOperator();
    std::string OpcodeName = getOpcodeName(InstPatOp, CGP);
    MVT::SimpleValueType VT = InstPatNode->getTypeNum(0);

    // For now, filter out instructions which just set a register to
    // an Operand, like MOV32ri.
    if (InstPatOp->isSubClassOf("Operand"))
      continue;

    // Check all the operands. For now only accept register operands.
    OperandsSignature Operands;
    for (unsigned i = 0, e = InstPatNode->getNumChildren(); i != e; ++i) {
      TreePatternNode *Op = InstPatNode->getChild(i);
      if (!Op->isLeaf())
        goto continue_label;
      DefInit *OpDI = dynamic_cast<DefInit*>(Op->getLeafValue());
      if (!OpDI)
        goto continue_label;
      Record *OpLeafRec = OpDI->getDef();
      if (!OpLeafRec->isSubClassOf("RegisterClass"))
        goto continue_label;
      const CodeGenRegisterClass *RC = &Target.getRegisterClass(OpLeafRec);
      if (!RC)
        goto continue_label;
      if (Op->getTypeNum(0) != VT)
        goto continue_label;
      Operands.Operands.push_back("r");
    }

    // If it's not a known signature, ignore it.
    if (!SimplePatterns.count(Operands))
      continue;

    // Ok, we found a pattern that we can handle. Remember it.
    {
      InstructionMemo Memo = {
        Pattern.getDstPattern()->getOperator()->getName(),
        DstRC
      };
      SimplePatterns[Operands][OpcodeName][VT] = Memo;
    }

  continue_label:;
  }

  OS << "#include \"llvm/CodeGen/FastISel.h\"\n";
  OS << "\n";
  OS << "namespace llvm {\n";
  OS << "\n";

  // Declare the target FastISel class.
  OS << "class " << InstNS << "FastISel : public llvm::FastISel {\n";
  for (OperandsOpcodeTypeMap::const_iterator OI = SimplePatterns.begin(),
       OE = SimplePatterns.end(); OI != OE; ++OI) {
    const OperandsSignature &Operands = OI->first;
    const OpcodeTypeMap &OTM = OI->second;

    for (OpcodeTypeMap::const_iterator I = OTM.begin(), E = OTM.end();
         I != E; ++I) {
      const std::string &Opcode = I->first;
      const TypeMap &TM = I->second;

      for (TypeMap::const_iterator TI = TM.begin(), TE = TM.end();
           TI != TE; ++TI) {
        MVT::SimpleValueType VT = TI->first;

        OS << "  unsigned FastEmit_" << getLegalCName(Opcode)
           << "_" << getLegalCName(getName(VT)) << "(";
        Operands.PrintParameters(OS);
        OS << ");\n";
      }

      OS << "  unsigned FastEmit_" << getLegalCName(Opcode)
         << "(MVT::SimpleValueType VT";
      if (!Operands.empty())
        OS << ", ";
      Operands.PrintParameters(OS);
      OS << ");\n";
    }

    OS << "unsigned FastEmit_";
    Operands.PrintManglingSuffix(OS);
    OS << "(MVT::SimpleValueType VT, ISD::NodeType Opcode";
    if (!Operands.empty())
      OS << ", ";
    Operands.PrintParameters(OS);
    OS << ");\n";
  }
  OS << "public:\n";
  OS << "  FastISel(MachineBasicBlock *mbb, MachineFunction *mf, ";
  OS << "const TargetInstrInfo *tii) : llvm::FastISel(mbb, mf, tii) {}\n";
  OS << "};\n";
  OS << "\n";

  // Define the target FastISel creation function.
  OS << "llvm::FastISel *" << InstNS
     << "createFastISel(MachineBasicBlock *mbb, MachineFunction *mf, ";
  OS << "const TargetInstrInfo *tii) {\n";
  OS << "  return new " << InstNS << "FastISel(mbb, mf, tii);\n";
  OS << "}\n";
  OS << "\n";

  // Now emit code for all the patterns that we collected.
  for (OperandsOpcodeTypeMap::const_iterator OI = SimplePatterns.begin(),
       OE = SimplePatterns.end(); OI != OE; ++OI) {
    const OperandsSignature &Operands = OI->first;
    const OpcodeTypeMap &OTM = OI->second;

    for (OpcodeTypeMap::const_iterator I = OTM.begin(), E = OTM.end();
         I != E; ++I) {
      const std::string &Opcode = I->first;
      const TypeMap &TM = I->second;

      OS << "// FastEmit functions for " << Opcode << ".\n";
      OS << "\n";

      // Emit one function for each opcode,type pair.
      for (TypeMap::const_iterator TI = TM.begin(), TE = TM.end();
           TI != TE; ++TI) {
        MVT::SimpleValueType VT = TI->first;
        const InstructionMemo &Memo = TI->second;

        OS << "unsigned " << InstNS << "FastISel::FastEmit_"
           << getLegalCName(Opcode)
           << "_" << getLegalCName(getName(VT)) << "(";
        Operands.PrintParameters(OS);
        OS << ") {\n";
        OS << "  return FastEmitInst_";
        Operands.PrintManglingSuffix(OS);
        OS << "(" << InstNS << Memo.Name << ", ";
        OS << InstNS << Memo.RC->getName() << "RegisterClass";
        if (!Operands.empty())
          OS << ", ";
        Operands.PrintArguments(OS);
        OS << ");\n";
        OS << "}\n";
        OS << "\n";
      }

      // Emit one function for the opcode that demultiplexes based on the type.
      OS << "unsigned " << InstNS << "FastISel::FastEmit_"
         << getLegalCName(Opcode) << "(MVT::SimpleValueType VT";
      if (!Operands.empty())
        OS << ", ";
      Operands.PrintParameters(OS);
      OS << ") {\n";
      OS << "  switch (VT) {\n";
      for (TypeMap::const_iterator TI = TM.begin(), TE = TM.end();
           TI != TE; ++TI) {
        MVT::SimpleValueType VT = TI->first;
        std::string TypeName = getName(VT);
        OS << "  case " << TypeName << ": return FastEmit_"
           << getLegalCName(Opcode) << "_" << getLegalCName(TypeName) << "(";
        Operands.PrintArguments(OS);
        OS << ");\n";
      }
      OS << "  default: return 0;\n";
      OS << "  }\n";
      OS << "}\n";
      OS << "\n";
    }

    // Emit one function for the operand signature that demultiplexes based
    // on opcode and type.
    OS << "unsigned " << InstNS << "FastISel::FastEmit_";
    Operands.PrintManglingSuffix(OS);
    OS << "(MVT::SimpleValueType VT, ISD::NodeType Opcode";
    if (!Operands.empty())
      OS << ", ";
    Operands.PrintParameters(OS);
    OS << ") {\n";
    OS << "  switch (Opcode) {\n";
    for (OpcodeTypeMap::const_iterator I = OTM.begin(), E = OTM.end();
         I != E; ++I) {
      const std::string &Opcode = I->first;

      OS << "  case " << Opcode << ": return FastEmit_"
         << getLegalCName(Opcode) << "(VT";
      if (!Operands.empty())
        OS << ", ";
      Operands.PrintArguments(OS);
      OS << ");\n";
    }
    OS << "  default: return 0;\n";
    OS << "  }\n";
    OS << "}\n";
    OS << "\n";
  }

  OS << "}\n";
}

// todo: really filter out Constants
<|endoftext|>


<commit_before>#include <iostream>
#include <string>

class LGS
{
private:
	int varsize;//x Anzahl der Variablen des lgs, Breite davon ist x+1
	int eqsize;//y Anzahl der Gleichungen, "Hhe" des lgs
	int varcount = 0; //Arbeitsvariable breite
	int eqcount = 0; //Arbeitsvariable hhe
	float **lgs; //Zwei ** wegen 2 dimensionen

public:
	//Anzahl der Variablen und Gleichungen sind gefordert
	//wichtig: wert an Adresse sollte von aussen nicht verndert werden
	LGS(int variable_num, int equation_num, float **matrix);

	~LGS();

	//Returnt gelstes LGS in Stufenform
	LGS Ref();

	//Returnt LGS in vollstndig gelster Version, MUSS mit LGS in REF Form aufgerufen werden
	LGS OnlyRRef();

	//Returnt direkt von Normalform zu Ergebnisform
	LGS RRef();

	//Returnt String des LGS
	std::string ToString();

	//Prft, ob lsung des LGS Punkt entspricht, LGS muss in RREf Form vorliegen
	bool IsSolutionPoint();

	//returnt Lsung in dyn. Float array, Lnge ist varsize - 1
	float *GetSolution();
};

//methodendefinitionen von LGS

//Anzahl der Variablen und Gleichungen sind gefordert
//wichtig: Wert an Adresse sollte von aussen nicht verndert werden
LGS::LGS(int variable_num, int equation_num, float **matrix)
{
	//Variablen einstellen
	varsize = variable_num;
	eqsize = equation_num;
	varcount = varsize;
	eqcount = eqsize - 1;
	//Lgs zuweisen
	lgs = matrix;
}

LGS::~LGS()
{
	for (int y = 0; y <= eqsize; y++)
	{
		delete[] lgs[y];
	}
}

//Returnt gelstes LGS in Stufenform
LGS LGS::Ref()
{
	int yzaehler; //Zaelvariable fuer berechnete Gleichungen
	int dgaenge; //Zaehlvariable fr Rechendurchgaenge
	int ypos = 0;//y Richtungsdurchlauf
	int xpos = 0;//x Richtungsdurchlauf
	int elimx = 0;//ist beginn der treppendurchlauefe in x richtung, zaehlt die eliminationsvorgaenge der variablen
	int start_step = 0;//ist beginn der treppendurchlauefe in y richtung, bestimmt, ab welcher Gleichung weiter eliminiert wird
	float puffer = 0;
	LGS Lgs_ref(varsize, eqsize, lgs);//LGS, dass bearbeitet wird

																		//Zhler hchstens quadratisch machen
	if (eqsize > varsize)
	{
		yzaehler = varsize;
	}
	else if (varsize > eqsize || varsize == eqsize)
	{
		yzaehler = eqsize - 1;
	}

	start_step = 0;
	for (elimx = 0; elimx <= varsize; elimx++)//elimx ist beginn der treppendurchlauefe in x richtung, zaehlt die eliminationsvorgaenge der variablen
	{
		for (ypos = start_step; ypos < yzaehler; ypos++)//y Richtungsdurchlauf
		{
			puffer = Lgs_ref.lgs[ypos + 1][elimx];
			for (xpos = elimx; xpos <= varsize; xpos++)//x Richtungsdurchlauf
			{
				//Variable wir eliminiert oder mit El9minationsgleichung subtrahiert
				Lgs_ref.lgs[ypos + 1][xpos] = Lgs_ref.lgs[ypos + 1][xpos] - ((Lgs_ref.lgs[start_step][xpos] / Lgs_ref.lgs[start_step][elimx]) * puffer);
			}
		}
		start_step++;//start_step ist beginn der treppendurchlauefe in y richtung, bestimmt, ab welcher Gleichung weiter eliminiert wird
	}

	return Lgs_ref;
}

//Return LGS in vollstndig gelster Version, MUSS mit LGS in REF Form aufgerufen werden
LGS LGS::OnlyRRef()
{
	int yzaehler; //Zaelvariable fuer berechnete Gleichungen
	int dgaenge; //Zaehlvariable fr Rechendurchgaenge
	int ypos = 0;//y Richtungsdurchlauf
	int xpos = 0;//x Richtungsdurchlauf
	LGS Lgs_rref(varsize, eqsize, lgs);//lgs sollte in ref form sein

																		 //Anfangs y-pos
	if (eqsize > varsize)
	{
		ypos = varsize;
	}
	else if (varsize > eqsize || varsize == eqsize)
	{
		ypos = eqsize - 1;
	}

	//LGS wird diagonal abgefahren von Unten rechts nach oben links
	for (xpos = varsize - 1; xpos >= 0; xpos--)
	{
		for (int varstep = xpos + 1; varstep < varsize; varstep++)
		{
			//Variable mit letztem Ergebnis multiplizieren, von Gleichungen subtrahieren
			Lgs_rref.lgs[ypos][varsize] -= Lgs_rref.lgs[ypos][varstep] * Lgs_rref.lgs[varstep][varsize];
			Lgs_rref.lgs[ypos][varstep] = 0;
		}
		//Gleichung durch Faktor von Var.
		Lgs_rref.lgs[ypos][varsize] /= Lgs_rref.lgs[ypos][xpos];
		Lgs_rref.lgs[ypos][xpos] = 1;
		ypos--;
	}

	return Lgs_rref;
}

//Returnt direkt von Normalform zu Ergebnisform
LGS LGS::RRef()
{
	LGS Solved(varsize, eqsize, lgs);
	Solved = Ref();
	Solved = OnlyRRef();
	return Solved;
}

//Returnt String des LGS
std::string LGS::ToString()
{
	std::string output = "";

	for (int row = 0; row <= eqcount; row++)//Schleife Zeilen
	{
		output += "[ ";
		for (int col = 0; col <= varcount; col++)//Schleife Spalten in einer Zeile
		{
			output += (std::to_string(lgs[row][col]) + " ");
		}
		output += "]\n";
	}

	return output;
}

bool LGS::IsSolutionPoint()
{
	//Prfen ob es berhaupt lsenbar ist
	if (varsize > eqsize)
	{
		return 0;
	}
	//Diagonal abfahren
	for (int i = 0; i < varsize; i++)
	{
		//Es sollte immer 1 dort sein
		if (lgs[i][i] == 0)
		{
			return 0;
		}
	}

	return 1;
}

float *LGS::GetSolution()
{
	//Lsungsspeicher
	float *sol = new float[varsize];
	//Rechte Seite des LGS abfahren
	for (int i = 0; i < varsize; i++)
	{
		sol[i] = lgs[varsize][i];
	}

	return sol;
}<commit_msg>changes<commit_after>#include <iostream>
#include <string>

class LGS
{
private:
	int varsize;//x Anzahl der Variablen des lgs, Breite davon ist x+1
	int eqsize;//y Anzahl der Gleichungen, "Hhe" des lgs
	int varcount = 0; //Arbeitsvariable breite
	int eqcount = 0; //Arbeitsvariable hhe
	float **lgs; //Zwei ** wegen 2 dimensionen

public:
	//Anzahl der Variablen und Gleichungen sind gefordert
	//wichtig: wert an Adresse sollte von aussen nicht verndert werden
	LGS(int variable_num, int equation_num, float **matrix);

	~LGS();

	//Returnt gelstes LGS in Stufenform
	LGS Ref();

	//Returnt LGS in vollstndig gelster Version, MUSS mit LGS in REF Form aufgerufen werden
	LGS OnlyRRef();

	//Returnt direkt von Normalform zu Ergebnisform
	LGS RRef();

	//Returnt String des LGS
	std::string ToString();

	//Prft, ob lsung des LGS Punkt entspricht, LGS muss in RREf Form vorliegen
	bool IsSolutionPoint();

	//returnt Lsung in dyn. Float array, Lnge ist varsize - 1
	float *GetSolution();
};

//methodendefinitionen von LGS

//Anzahl der Variablen und Gleichungen sind gefordert
//wichtig: Wert an Adresse sollte von aussen nicht verndert werden
LGS::LGS(int variable_num, int equation_num, float **matrix)
{
	//Variablen einstellen
	varsize = variable_num;
	eqsize = equation_num;
	varcount = varsize;
	eqcount = eqsize - 1;
	//Lgs zuweisen
	lgs = matrix;
}

LGS::~LGS()
{
	for (int y = 0; y <= eqsize; y++)
	{
		delete[] lgs[y];
	}
}

//Returnt gelstes LGS in Stufenform
LGS LGS::Ref()
{
	int yzaehler; //Zaelvariable fuer berechnete Gleichungen
	int dgaenge; //Zaehlvariable fr Rechendurchgaenge
	int ypos = 0;//y Richtungsdurchlauf
	int xpos = 0;//x Richtungsdurchlauf
	int elimx = 0;//ist beginn der treppendurchlauefe in x richtung, zaehlt die eliminationsvorgaenge der variablen
	int start_step = 0;//ist beginn der treppendurchlauefe in y richtung, bestimmt, ab welcher Gleichung weiter eliminiert wird
	float puffer = 0;
	LGS Lgs_ref(varsize, eqsize, lgs);//LGS, dass bearbeitet wird

																		//Zhler hchstens quadratisch machen
	if (eqsize > varsize)
	{
		yzaehler = varsize;
	}
	else if (varsize > eqsize || varsize == eqsize)
	{
		yzaehler = eqsize - 1;
	}

	start_step = 0;
	for (elimx = 0; elimx <= varsize; elimx++)//elimx ist beginn der treppendurchlauefe in x richtung, zaehlt die eliminationsvorgaenge der variablen
	{
		for (ypos = start_step; ypos < yzaehler; ypos++)//y Richtungsdurchlauf
		{
			puffer = Lgs_ref.lgs[ypos + 1][elimx];
			for (xpos = elimx; xpos <= varsize; xpos++)//x Richtungsdurchlauf
			{
				//Variable wir eliminiert oder mit El9minationsgleichung subtrahiert
				Lgs_ref.lgs[ypos + 1][xpos] = Lgs_ref.lgs[ypos + 1][xpos] - ((Lgs_ref.lgs[start_step][xpos] / Lgs_ref.lgs[start_step][elimx]) * puffer);
			}
		}
		start_step++;//start_step ist beginn der treppendurchlauefe in y richtung, bestimmt, ab welcher Gleichung weiter eliminiert wird
	}

	return Lgs_ref;
}

//Return LGS in vollstndig gelster Version, MUSS mit LGS in REF Form aufgerufen werden
LGS LGS::OnlyRRef()
{
	int yzaehler; //Zaelvariable fuer berechnete Gleichungen
	int dgaenge; //Zaehlvariable fr Rechendurchgaenge
	int ypos = 0;//y Richtungsdurchlauf
	int xpos = 0;//x Richtungsdurchlauf
	LGS Lgs_rref(varsize, eqsize, lgs);//lgs sollte in ref form sein

																		 //Anfangs y-pos
	if (eqsize > varsize)
	{
		ypos = varsize;
	}
	else if (varsize > eqsize || varsize == eqsize)
	{
		ypos = eqsize - 1;
	}

	//LGS wird diagonal abgefahren von Unten rechts nach oben links
	for (xpos = varsize - 1; xpos >= 0; xpos--)
	{
		for (int varstep = xpos + 1; varstep < varsize; varstep++)
		{
			//Variable mit letztem Ergebnis multiplizieren, von Gleichungen subtrahieren
			Lgs_rref.lgs[ypos][varsize] -= Lgs_rref.lgs[ypos][varstep] * Lgs_rref.lgs[varstep][varsize];
			Lgs_rref.lgs[ypos][varstep] = 0;
		}
		//Gleichung durch Faktor von Var.
		Lgs_rref.lgs[ypos][varsize] /= Lgs_rref.lgs[ypos][xpos];
		Lgs_rref.lgs[ypos][xpos] = 1;
		ypos--;
	}

	return Lgs_rref;
}

//Returnt direkt von Normalform zu Ergebnisform
LGS LGS::RRef()
{
	LGS Solved(varsize, eqsize, lgs);
	Solved = Ref();
	Solved = OnlyRRef();
	return Solved;
}

//Returnt String des LGS
std::string LGS::ToString()
{
	std::string output = "";

	for (int row = 0; row <= eqcount; row++)//Schleife Zeilen
	{
		output += "[ ";
		for (int col = 0; col <= varcount; col++)//Schleife Spalten in einer Zeile
		{
			output += (std::to_string(lgs[row][col]) + " ");
		}
		output += "]\n";
	}

	return output;
}

bool LGS::IsSolutionPoint()
{
	//Prfen, ob es berhaupt lsenbar ist
	if (varsize > eqsize)
	{
		return 0;
	}
	//Diagonal abfahren
	for (int i = 0; i < varsize; i++)
	{
		//Es sollte immer 1 dort sein
		if (lgs[i][i] == 0)
		{
			return 0;
		}
	}

	return 1;
}

float *LGS::GetSolution()
{
	//Lsungsspeicher
	float *sol = new float[varsize];
	//Rechte Seite des LGS abfahren
	for (int i = 0; i < varsize; i++)
	{
		sol[i] = lgs[varsize][i];
	}

	return sol;
}<|endoftext|>


<commit_before>// License: Apache 2.0. See LICENSE file in root directory.
// Copyright(c) 2015 Intel Corporation. All Rights Reserved.

#ifdef RS2_USE_WMF_BACKEND

#if (_MSC_FULL_VER < 180031101)
#error At least Visual Studio 2013 Update 4 is required to compile this backend
#endif

#ifndef NOMINMAX
#define NOMINMAX
#endif

#include "../types.h"
#include "win-hid.h"
#include "win-helpers.h"

#include <PortableDeviceTypes.h>
//#include <PortableDeviceClassExtension.h>
#include <PortableDevice.h>
#include <Windows.h>
#include <Sensorsapi.h>
#include <sensors.h>
#include <SensAPI.h>
#include <initguid.h>
#include <propkeydef.h>
#include <comutil.h>

#pragma comment(lib, "Sensorsapi.lib")
#pragma comment(lib, "PortableDeviceGuids.lib")

namespace librealsense
{
    namespace platform
    {
        class sensor_events : public ISensorEvents
        {
        public:
            virtual ~sensor_events() = default;

            explicit sensor_events(hid_callback callback) : m_cRef(0), _callback(callback) {}

            STDMETHODIMP QueryInterface(REFIID iid, void** ppv)
            {
                if (ppv == NULL)
                {
                    return E_POINTER;
                }
                if (iid == __uuidof(IUnknown))
                {
                    *ppv = static_cast<IUnknown*>(this);
                }
                else if (iid == __uuidof(ISensorEvents))
                {
                    *ppv = static_cast<ISensorEvents*>(this);
                }
                else
                {
                    *ppv = NULL;
                    return E_NOINTERFACE;
                }
                AddRef();
                return S_OK;
            }

            STDMETHODIMP_(ULONG) AddRef()
            {
                return InterlockedIncrement(&m_cRef);
            }

            STDMETHODIMP_(ULONG) Release()
            {
                ULONG count = InterlockedDecrement(&m_cRef);
                if (count == 0)
                {
                    delete this;
                    return 0;
                }
                return count;
            }

            //
            // ISensorEvents methods.
            //

            STDMETHODIMP OnEvent(
                ISensor *pSensor,
                REFGUID eventID,
                IPortableDeviceValues *pEventData)
            {
                HRESULT hr = S_OK;

                // Handle custom events here.

                return hr;
            }

            STDMETHODIMP OnDataUpdated(ISensor *pSensor, ISensorDataReport *report)
            {
                if (NULL == report ||
                    NULL == pSensor)
                {
                    return E_INVALIDARG;
                }

                SYSTEMTIME time;
                report->GetTimestamp(&time);

                PROPVARIANT var = {};
                // Custom timestamp low
                auto hr = (report->GetSensorValue(SENSOR_DATA_TYPE_CUSTOM_VALUE1, &var));
                if (FAILED(hr)) return S_OK;
                auto customTimestampLow = var.ulVal;

                // Custom timestamp high
                CHECK_HR(report->GetSensorValue(SENSOR_DATA_TYPE_CUSTOM_VALUE2, &var));
                auto customTimestampHigh = var.ulVal;

                // Raw X
                CHECK_HR(report->GetSensorValue(SENSOR_DATA_TYPE_CUSTOM_VALUE3, &var));
                auto rawX = var.iVal;

                // Raw Y
                CHECK_HR(report->GetSensorValue(SENSOR_DATA_TYPE_CUSTOM_VALUE4, &var));
                auto rawY = var.iVal;

                // Raw Z
                CHECK_HR(report->GetSensorValue(SENSOR_DATA_TYPE_CUSTOM_VALUE5, &var));
                auto rawZ = var.iVal;

                PropVariantClear(&var);

                sensor_data d;
                hid_sensor_data data;

                data.x = rawX;
                data.y = rawY;
                data.z = rawZ;
                data.ts_low = customTimestampLow;
                data.ts_high = customTimestampHigh;
                d.sensor.name = "";

                d.fo.pixels = &data;
                d.fo.metadata = NULL;
                d.fo.frame_size = sizeof(data);
                _callback(d);

                return S_OK;
            }

            STDMETHODIMP OnLeave(
                REFSENSOR_ID sensorID)
            {
                HRESULT hr = S_OK;

                // Peform any housekeeping tasks for the sensor that is leaving.
                // For example, if you have maintained a reference to the sensor,
                // release it now and set the pointer to NULL.

                return hr;
            }

            STDMETHODIMP OnStateChanged(
                ISensor* pSensor,
                SensorState state)
            {
                HRESULT hr = S_OK;

                if (NULL == pSensor)
                {
                    return E_INVALIDARG;
                }

                if (state == SENSOR_STATE_READY)
                {
                    wprintf_s(L"\nTime sensor is now ready.");
                }
                else if (state == SENSOR_STATE_ACCESS_DENIED)
                {
                    wprintf_s(L"\nNo permission for the time sensor.\n");
                    wprintf_s(L"Enable the sensor in the control panel.\n");
                }

                return hr;
            }

        private:
            long m_cRef;
            hid_callback _callback;
        };

        void wmf_hid_device::open(const std::vector<hid_profile>&iio_profiles)
        {
        }

        void wmf_hid_device::close()
        {
        }

        void wmf_hid_device::stop_capture()
        {
            _sensor->SetEventSink(NULL);
            _cb = nullptr;

        }

        void wmf_hid_device::start_capture(hid_callback callback)
        {
            // Hack, start default profile
            _cb = new sensor_events(callback);
            ISensorEvents* sensorEvents = nullptr;
            CHECK_HR(_cb->QueryInterface(IID_PPV_ARGS(&sensorEvents)));
            CHECK_HR(_sensor->SetEventSink(sensorEvents));
        }

        std::vector<hid_sensor> wmf_hid_device::get_sensors()
        {
            std::vector<hid_sensor> sensors;

            HRESULT res = S_OK;
            BSTR fName{};
            LOG_HR(res = _sensor->GetFriendlyName(&fName));
            if (FAILED(res)) fName = L"Unidentified HID Sensor";

            sensors.push_back({ std::string(fName, fName + wcslen(fName)) });

            SysFreeString(fName);

            return sensors;
        }

        std::vector<uint8_t> wmf_hid_device::get_custom_report_data(const std::string & custom_sensor_name, const std::string & report_name, custom_sensor_report_field report_field)
        {
            return std::vector<uint8_t>();
        }

        void wmf_hid_device::foreach_hid_device(std::function<void(hid_device_info, CComPtr<ISensor>)> action)
        {
            try
            {
                CComPtr<ISensorManager> pSensorManager = nullptr;
                CComPtr<ISensorCollection> pSensorColl = nullptr;
                CComPtr<ISensor> pSensor = nullptr;
                ULONG uCount{};
                HRESULT res{};

                CComPtr<ISensorDataReport> ppDataReport;

                CHECK_HR(CoCreateInstance(CLSID_SensorManager, NULL,
                         CLSCTX_INPROC_SERVER,
                         IID_PPV_ARGS(&pSensorManager)));

                LOG_HR(res=pSensorManager->GetSensorsByCategory(SENSOR_CATEGORY_ALL, &pSensorColl));
                if (SUCCEEDED(res))
                {
                    CHECK_HR(pSensorColl->GetCount(&uCount));

                    for (ULONG i = 0; i < uCount; i++)
                    {
                        if (SUCCEEDED(pSensorColl->GetAt(i, &pSensor.p)))
                        {
                            BSTR fName{};
                            LOG_HR(res = pSensor->GetFriendlyName(&fName));
                            if (FAILED(res)) fName= L"Unidentified HID sensor";

                            SENSOR_ID id{};
                            CHECK_HR(pSensor->GetID(&id));

                            SENSOR_TYPE_ID type{};
                            CHECK_HR(pSensor->GetType(&type));

                            CComPtr<IPortableDeviceValues> pValues = nullptr;  // Output

                            hid_device_info info{};

                            auto hr = pSensor->GetProperties(nullptr, &pValues);
                            DWORD cVals = 0; // Count of returned properties.
                            if (SUCCEEDED(hr))
                            {
                                // Get the number of values returned.
                                hr = pValues->GetCount(&cVals);
                                if (SUCCEEDED(hr))
                                {
                                    PROPERTYKEY pk; // Keys
                                    PROPVARIANT pv = {}; // Values

                                    // Loop through the values
                                    for (DWORD j = 0; j < cVals; j++)
                                    {
                                        // Get the value at the current index.
                                        hr = pValues->GetAt(j, &pk, &pv);
                                        if (SUCCEEDED(hr))
                                        {
                                            if (IsEqualPropertyKey(pk, SENSOR_PROPERTY_DEVICE_PATH))
                                            {
                                                info.device_path = std::string(pv.pwszVal, pv.pwszVal + wcslen(pv.pwszVal));
                                                info.id = std::string(fName, fName + wcslen(fName));

                                                uint16_t vid, pid, mi;
                                                std::string uid;
                                                if (parse_usb_path(vid, pid, mi, uid, info.device_path))
                                                {
                                                    info.unique_id = "*";
                                                    info.pid = to_string() << std::hex << pid;
                                                    info.vid = to_string() << std::hex << vid;
                                                }
                                            }

                                            //if (IsEqualPropertyKey(pk, SENSOR_PROPERTY_MODEL))
                                            //{
                                            //    info.pid = std::string(pv.pwszVal, pv.pwszVal + wcslen(pv.pwszVal));
                                            //}
                                        }
                                        PropVariantClear(&pv);
                                    }
                                }
                            }

                            action(info, pSensor);

                            //if (wcsstr(fName, L"Accelerometer") != NULL)
                            //if (wcsstr(fName, L"Gyroscope") != NULL)
                            //{
                            //    auto callback = new SensorEvents();
                            //    ISensorEvents* sensorEvents;
                            //    HRESULT hr = callback->QueryInterface(IID_PPV_ARGS(&sensorEvents));
                            //    hr = pSensor->SetEventSink(sensorEvents);
                            //    //for (int i = 0; i < 10000; i++)
                            //    //{
                            //    //    hr = pSensor->GetData(&ppDataReport);
                            //    //    if (ppDataReport != NULL)
                            //    //    {
                            //    //        SYSTEMTIME time;
                            //    //        ppDataReport->GetTimestamp(&time);

                            //    //        printf("%d.%d.%d %d:%d:%d.%d\n", time.wDay, time.wMonth, time.wYear, time.wHour, time.wMinute, time.wSecond, time.wMilliseconds);

                            //    //        IPortableDeviceValues* values;
                            //    //        ppDataReport->GetSensorValues(NULL, &values);

                            //    //        DWORD valuesCount = 0;
                            //    //        hr = values->GetCount(&valuesCount);
                            //    //        if (SUCCEEDED(hr))
                            //    //        {
                            //    //            PROPERTYKEY pk; // Keys
                            //    //            PROPVARIANT pv = {}; // Values

                            //    //            for (DWORD i = 0; i < valuesCount; i++)
                            //    //            {
                            //    //                // Get the value at the current index.
                            //    //                hr = values->GetAt(i, &pk, &pv);
                            //    //                if (SUCCEEDED(hr))
                            //    //                {
                            //    //                    if (IsEqualPropertyKey(pk, SENSOR_DATA_TYPE_CUSTOM_USAGE))
                            //    //                    {
                            //    //                        wprintf_s(L"\Acceleration X: %lu\n", pv.ulVal);
                            //    //                    }
                            //    //                }
                            //    //            }
                            //    //        }
                            //    //        //SENSOR_DATA_TYPE_ACCELERATION_X_G
                            //    //    }
                            //    //}
                            //    //printf("\n");
                            //}
                            SysFreeString(fName);
                        }
                    }
                }
            }
            catch (...)
            {
                LOG_INFO("Could not enumerate HID devices!");
            }
        }
    }
}

#endif
<commit_msg>disable hid devices enumeration on windows<commit_after>// License: Apache 2.0. See LICENSE file in root directory.
// Copyright(c) 2015 Intel Corporation. All Rights Reserved.

#ifdef RS2_USE_WMF_BACKEND

#if (_MSC_FULL_VER < 180031101)
#error At least Visual Studio 2013 Update 4 is required to compile this backend
#endif

#ifndef NOMINMAX
#define NOMINMAX
#endif

#include "../types.h"
#include "win-hid.h"
#include "win-helpers.h"

#include <PortableDeviceTypes.h>
//#include <PortableDeviceClassExtension.h>
#include <PortableDevice.h>
#include <Windows.h>
#include <Sensorsapi.h>
#include <sensors.h>
#include <SensAPI.h>
#include <initguid.h>
#include <propkeydef.h>
#include <comutil.h>

#pragma comment(lib, "Sensorsapi.lib")
#pragma comment(lib, "PortableDeviceGuids.lib")

namespace librealsense
{
    namespace platform
    {
        class sensor_events : public ISensorEvents
        {
        public:
            virtual ~sensor_events() = default;

            explicit sensor_events(hid_callback callback) : m_cRef(0), _callback(callback) {}

            STDMETHODIMP QueryInterface(REFIID iid, void** ppv)
            {
                if (ppv == NULL)
                {
                    return E_POINTER;
                }
                if (iid == __uuidof(IUnknown))
                {
                    *ppv = static_cast<IUnknown*>(this);
                }
                else if (iid == __uuidof(ISensorEvents))
                {
                    *ppv = static_cast<ISensorEvents*>(this);
                }
                else
                {
                    *ppv = NULL;
                    return E_NOINTERFACE;
                }
                AddRef();
                return S_OK;
            }

            STDMETHODIMP_(ULONG) AddRef()
            {
                return InterlockedIncrement(&m_cRef);
            }

            STDMETHODIMP_(ULONG) Release()
            {
                ULONG count = InterlockedDecrement(&m_cRef);
                if (count == 0)
                {
                    delete this;
                    return 0;
                }
                return count;
            }

            //
            // ISensorEvents methods.
            //

            STDMETHODIMP OnEvent(
                ISensor *pSensor,
                REFGUID eventID,
                IPortableDeviceValues *pEventData)
            {
                HRESULT hr = S_OK;

                // Handle custom events here.

                return hr;
            }

            STDMETHODIMP OnDataUpdated(ISensor *pSensor, ISensorDataReport *report)
            {
                if (NULL == report ||
                    NULL == pSensor)
                {
                    return E_INVALIDARG;
                }

                SYSTEMTIME time;
                report->GetTimestamp(&time);

                PROPVARIANT var = {};
                // Custom timestamp low
                auto hr = (report->GetSensorValue(SENSOR_DATA_TYPE_CUSTOM_VALUE1, &var));
                if (FAILED(hr)) return S_OK;
                auto customTimestampLow = var.ulVal;

                // Custom timestamp high
                CHECK_HR(report->GetSensorValue(SENSOR_DATA_TYPE_CUSTOM_VALUE2, &var));
                auto customTimestampHigh = var.ulVal;

                // Raw X
                CHECK_HR(report->GetSensorValue(SENSOR_DATA_TYPE_CUSTOM_VALUE3, &var));
                auto rawX = var.iVal;

                // Raw Y
                CHECK_HR(report->GetSensorValue(SENSOR_DATA_TYPE_CUSTOM_VALUE4, &var));
                auto rawY = var.iVal;

                // Raw Z
                CHECK_HR(report->GetSensorValue(SENSOR_DATA_TYPE_CUSTOM_VALUE5, &var));
                auto rawZ = var.iVal;

                PropVariantClear(&var);

                sensor_data d;
                hid_sensor_data data;

                data.x = rawX;
                data.y = rawY;
                data.z = rawZ;
                data.ts_low = customTimestampLow;
                data.ts_high = customTimestampHigh;
                d.sensor.name = "";

                d.fo.pixels = &data;
                d.fo.metadata = NULL;
                d.fo.frame_size = sizeof(data);
                _callback(d);

                return S_OK;
            }

            STDMETHODIMP OnLeave(
                REFSENSOR_ID sensorID)
            {
                HRESULT hr = S_OK;

                // Peform any housekeeping tasks for the sensor that is leaving.
                // For example, if you have maintained a reference to the sensor,
                // release it now and set the pointer to NULL.

                return hr;
            }

            STDMETHODIMP OnStateChanged(
                ISensor* pSensor,
                SensorState state)
            {
                HRESULT hr = S_OK;

                if (NULL == pSensor)
                {
                    return E_INVALIDARG;
                }

                if (state == SENSOR_STATE_READY)
                {
                    wprintf_s(L"\nTime sensor is now ready.");
                }
                else if (state == SENSOR_STATE_ACCESS_DENIED)
                {
                    wprintf_s(L"\nNo permission for the time sensor.\n");
                    wprintf_s(L"Enable the sensor in the control panel.\n");
                }

                return hr;
            }

        private:
            long m_cRef;
            hid_callback _callback;
        };

        void wmf_hid_device::open(const std::vector<hid_profile>&iio_profiles)
        {
        }

        void wmf_hid_device::close()
        {
        }

        void wmf_hid_device::stop_capture()
        {
            _sensor->SetEventSink(NULL);
            _cb = nullptr;

        }

        void wmf_hid_device::start_capture(hid_callback callback)
        {
            // Hack, start default profile
            _cb = new sensor_events(callback);
            ISensorEvents* sensorEvents = nullptr;
            CHECK_HR(_cb->QueryInterface(IID_PPV_ARGS(&sensorEvents)));
            CHECK_HR(_sensor->SetEventSink(sensorEvents));
        }

        std::vector<hid_sensor> wmf_hid_device::get_sensors()
        {
            std::vector<hid_sensor> sensors;

            HRESULT res = S_OK;
            BSTR fName{};
            LOG_HR(res = _sensor->GetFriendlyName(&fName));
            if (FAILED(res)) fName = L"Unidentified HID Sensor";

            sensors.push_back({ std::string(fName, fName + wcslen(fName)) });

            SysFreeString(fName);

            return sensors;
        }

        std::vector<uint8_t> wmf_hid_device::get_custom_report_data(const std::string & custom_sensor_name, const std::string & report_name, custom_sensor_report_field report_field)
        {
            return std::vector<uint8_t>();
        }

        void wmf_hid_device::foreach_hid_device(std::function<void(hid_device_info, CComPtr<ISensor>)> action)
        {
            return; // HID devices aren't supported on Windows OS
            try
            {
                CComPtr<ISensorManager> pSensorManager = nullptr;
                CComPtr<ISensorCollection> pSensorColl = nullptr;
                CComPtr<ISensor> pSensor = nullptr;
                ULONG uCount{};
                HRESULT res{};

                CComPtr<ISensorDataReport> ppDataReport;

                CHECK_HR(CoCreateInstance(CLSID_SensorManager, NULL,
                         CLSCTX_INPROC_SERVER,
                         IID_PPV_ARGS(&pSensorManager)));

                LOG_HR(res=pSensorManager->GetSensorsByCategory(SENSOR_CATEGORY_ALL, &pSensorColl));
                if (SUCCEEDED(res))
                {
                    CHECK_HR(pSensorColl->GetCount(&uCount));

                    for (ULONG i = 0; i < uCount; i++)
                    {
                        if (SUCCEEDED(pSensorColl->GetAt(i, &pSensor.p)))
                        {
                            BSTR fName{};
                            LOG_HR(res = pSensor->GetFriendlyName(&fName));
                            if (FAILED(res)) fName= L"Unidentified HID sensor";

                            SENSOR_ID id{};
                            CHECK_HR(pSensor->GetID(&id));

                            SENSOR_TYPE_ID type{};
                            CHECK_HR(pSensor->GetType(&type));

                            CComPtr<IPortableDeviceValues> pValues = nullptr;  // Output

                            hid_device_info info{};

                            auto hr = pSensor->GetProperties(nullptr, &pValues);
                            DWORD cVals = 0; // Count of returned properties.
                            if (SUCCEEDED(hr))
                            {
                                // Get the number of values returned.
                                hr = pValues->GetCount(&cVals);
                                if (SUCCEEDED(hr))
                                {
                                    PROPERTYKEY pk; // Keys
                                    PROPVARIANT pv = {}; // Values

                                    // Loop through the values
                                    for (DWORD j = 0; j < cVals; j++)
                                    {
                                        // Get the value at the current index.
                                        hr = pValues->GetAt(j, &pk, &pv);
                                        if (SUCCEEDED(hr))
                                        {
                                            if (IsEqualPropertyKey(pk, SENSOR_PROPERTY_DEVICE_PATH))
                                            {
                                                info.device_path = std::string(pv.pwszVal, pv.pwszVal + wcslen(pv.pwszVal));
                                                info.id = std::string(fName, fName + wcslen(fName));

                                                uint16_t vid, pid, mi;
                                                std::string uid;
                                                if (parse_usb_path(vid, pid, mi, uid, info.device_path))
                                                {
                                                    info.unique_id = "*";
                                                    info.pid = to_string() << std::hex << pid;
                                                    info.vid = to_string() << std::hex << vid;
                                                }
                                            }

                                            //if (IsEqualPropertyKey(pk, SENSOR_PROPERTY_MODEL))
                                            //{
                                            //    info.pid = std::string(pv.pwszVal, pv.pwszVal + wcslen(pv.pwszVal));
                                            //}
                                        }
                                        PropVariantClear(&pv);
                                    }
                                }
                            }

                            action(info, pSensor);

                            //if (wcsstr(fName, L"Accelerometer") != NULL)
                            //if (wcsstr(fName, L"Gyroscope") != NULL)
                            //{
                            //    auto callback = new SensorEvents();
                            //    ISensorEvents* sensorEvents;
                            //    HRESULT hr = callback->QueryInterface(IID_PPV_ARGS(&sensorEvents));
                            //    hr = pSensor->SetEventSink(sensorEvents);
                            //    //for (int i = 0; i < 10000; i++)
                            //    //{
                            //    //    hr = pSensor->GetData(&ppDataReport);
                            //    //    if (ppDataReport != NULL)
                            //    //    {
                            //    //        SYSTEMTIME time;
                            //    //        ppDataReport->GetTimestamp(&time);

                            //    //        printf("%d.%d.%d %d:%d:%d.%d\n", time.wDay, time.wMonth, time.wYear, time.wHour, time.wMinute, time.wSecond, time.wMilliseconds);

                            //    //        IPortableDeviceValues* values;
                            //    //        ppDataReport->GetSensorValues(NULL, &values);

                            //    //        DWORD valuesCount = 0;
                            //    //        hr = values->GetCount(&valuesCount);
                            //    //        if (SUCCEEDED(hr))
                            //    //        {
                            //    //            PROPERTYKEY pk; // Keys
                            //    //            PROPVARIANT pv = {}; // Values

                            //    //            for (DWORD i = 0; i < valuesCount; i++)
                            //    //            {
                            //    //                // Get the value at the current index.
                            //    //                hr = values->GetAt(i, &pk, &pv);
                            //    //                if (SUCCEEDED(hr))
                            //    //                {
                            //    //                    if (IsEqualPropertyKey(pk, SENSOR_DATA_TYPE_CUSTOM_USAGE))
                            //    //                    {
                            //    //                        wprintf_s(L"\Acceleration X: %lu\n", pv.ulVal);
                            //    //                    }
                            //    //                }
                            //    //            }
                            //    //        }
                            //    //        //SENSOR_DATA_TYPE_ACCELERATION_X_G
                            //    //    }
                            //    //}
                            //    //printf("\n");
                            //}
                            SysFreeString(fName);
                        }
                    }
                }
            }
            catch (...)
            {
                LOG_INFO("Could not enumerate HID devices!");
            }
        }
    }
}

#endif
<|endoftext|>


<commit_before>//
//  rule.cpp
//  Parse
//
//  Created by Andrew Hunter on 30/04/2011.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#include "rule.h"
#include "standard_items.h"

using namespace contextfree;

/// \brief Creates a rule (with the empty nonterminal)
rule::rule()
: m_NonTerminal(new empty_item(), true){
}

/// \brief Creates a copy of a rule
rule::rule(const rule& copyFrom)
: m_NonTerminal(copyFrom.m_NonTerminal)
, m_Items(copyFrom.m_Items) {
}

/// \brief Creates a copy of a rule with an alternative nonterminal
rule::rule(const rule& copyFrom, const item_container& nonTerminal)
: m_NonTerminal(nonTerminal)
, m_Items(copyFrom.m_Items) {
}

/// \brief Creates an empty rule, which reduces to the specified item
rule::rule(const item_container& nonTerminal)
: m_NonTerminal(nonTerminal) {
}

/// \brief Creates an empty rule with a nonterminal identifier
rule::rule(const int newNt)
: m_NonTerminal(new contextfree::nonterminal(newNt), true) {
}

/// \brief Copies the content of a rule into this one
rule& rule::operator=(const rule& copyFrom) {
    m_NonTerminal   = copyFrom.m_NonTerminal;
    m_Items         = copyFrom.m_Items;

    return *this;
}

/// \brief Orders this rule relative to another by comparing only the items
int rule::compare_items(const rule& compareTo) const {
    // Number of items is the fastest thing to compare, so check that first
    if (m_Items.size() < compareTo.m_Items.size())  return -1;
    if (m_Items.size() > compareTo.m_Items.size())  return 1;

    // Need to compare each item in turn
    item_list::const_iterator ourItem   = m_Items.begin();
    item_list::const_iterator theirItem = compareTo.begin();

    for (;ourItem != m_Items.end() && theirItem != compareTo.end(); ourItem++, theirItem++) {
        if (*ourItem < *theirItem) return -1;
        if (*ourItem > *theirItem) return 1;
    }

    return 0;
}

/// \brief Orders this rule relative to another
bool rule::operator<(const rule& compareTo) const {
    // Number of items is the fastest thing to compare, so check that first
    if (m_Items.size() < compareTo.m_Items.size())  return true;
    if (m_Items.size() > compareTo.m_Items.size())  return false;

    // The nonterminal should be reasonably fast to compare
    if (m_NonTerminal < compareTo.m_NonTerminal)    return true;

    // Compare the items
    return compare_items(compareTo) < 0;
}

/// \brief Determines if this rule is the same as another
bool rule::operator==(const rule& compareTo) const {
    // Number of items is the fastest thing to compare, so check that first
    if (m_Items.size() != compareTo.m_Items.size()) return false;

    // The nonterminal should be reasonably fast to compare
    if (m_NonTerminal != compareTo.m_NonTerminal)   return false;

    // Need to compare each item in turn
    item_list::const_iterator ourItem   = m_Items.begin();
    item_list::const_iterator theirItem = compareTo.begin();

    for (;ourItem != m_Items.end() && theirItem != compareTo.end(); ourItem++, theirItem++) {
        if (*ourItem != *theirItem) return false;
    }

    return true;
}

/// \brief Appends the specified item to this rule
rule& rule::operator<<(const item_container& item) {
    // Add this item to the list of items
    m_Items.push_back(item);

    return *this;
}

/// \brief Appends the production in the specified rule to this item
rule& rule::operator<<(const rule& rule) {
    for (iterator it = rule.begin(); it != rule.end(); it++) {
        operator<<(*it);
    }
    return *this;
}

/// \brief Returns the identifier for this rule in the specified grammar
int rule::identifier(const grammar& gram) const {
    if (&gram == m_LastGrammar) return m_Identifier;

    m_LastGrammar = &gram;
    return m_Identifier = gram.identifier_for_rule(*this);
}
<commit_msg>Fixed dumb issue with operator< when applied to rules - was only testing the nonterminal for less than and assuming that nonterminals which were greater than were the same :-/<commit_after>//
//  rule.cpp
//  Parse
//
//  Created by Andrew Hunter on 30/04/2011.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#include "rule.h"
#include "standard_items.h"

using namespace contextfree;

/// \brief Creates a rule (with the empty nonterminal)
rule::rule()
: m_NonTerminal(new empty_item(), true){
}

/// \brief Creates a copy of a rule
rule::rule(const rule& copyFrom)
: m_NonTerminal(copyFrom.m_NonTerminal)
, m_Items(copyFrom.m_Items) {
}

/// \brief Creates a copy of a rule with an alternative nonterminal
rule::rule(const rule& copyFrom, const item_container& nonTerminal)
: m_NonTerminal(nonTerminal)
, m_Items(copyFrom.m_Items) {
}

/// \brief Creates an empty rule, which reduces to the specified item
rule::rule(const item_container& nonTerminal)
: m_NonTerminal(nonTerminal) {
}

/// \brief Creates an empty rule with a nonterminal identifier
rule::rule(const int newNt)
: m_NonTerminal(new contextfree::nonterminal(newNt), true) {
}

/// \brief Copies the content of a rule into this one
rule& rule::operator=(const rule& copyFrom) {
    m_NonTerminal   = copyFrom.m_NonTerminal;
    m_Items         = copyFrom.m_Items;

    return *this;
}

/// \brief Orders this rule relative to another by comparing only the items
int rule::compare_items(const rule& compareTo) const {
    // Number of items is the fastest thing to compare, so check that first
    if (m_Items.size() < compareTo.m_Items.size())  return -1;
    if (m_Items.size() > compareTo.m_Items.size())  return 1;

    // Need to compare each item in turn
    item_list::const_iterator ourItem   = m_Items.begin();
    item_list::const_iterator theirItem = compareTo.begin();

    for (;ourItem != m_Items.end() && theirItem != compareTo.end(); ourItem++, theirItem++) {
        if (*ourItem < *theirItem) return -1;
        if (*ourItem > *theirItem) return 1;
    }

    return 0;
}

/// \brief Orders this rule relative to another
bool rule::operator<(const rule& compareTo) const {
    // Number of items is the fastest thing to compare, so check that first
    if (m_Items.size() < compareTo.m_Items.size())  return true;
    if (m_Items.size() > compareTo.m_Items.size())  return false;

    // The nonterminal should be reasonably fast to compare
    if (m_NonTerminal < compareTo.m_NonTerminal)    return true;
    if (m_NonTerminal > compareTo.m_NonTerminal)    return false;

    // Compare the items
    return compare_items(compareTo) < 0;
}

/// \brief Determines if this rule is the same as another
bool rule::operator==(const rule& compareTo) const {
    // Number of items is the fastest thing to compare, so check that first
    if (m_Items.size() != compareTo.m_Items.size()) return false;

    // The nonterminal should be reasonably fast to compare
    if (m_NonTerminal != compareTo.m_NonTerminal)   return false;

    // Need to compare each item in turn
    item_list::const_iterator ourItem   = m_Items.begin();
    item_list::const_iterator theirItem = compareTo.begin();

    for (;ourItem != m_Items.end() && theirItem != compareTo.end(); ourItem++, theirItem++) {
        if (*ourItem != *theirItem) return false;
    }

    return true;
}

/// \brief Appends the specified item to this rule
rule& rule::operator<<(const item_container& item) {
    // Add this item to the list of items
    m_Items.push_back(item);

    return *this;
}

/// \brief Appends the production in the specified rule to this item
rule& rule::operator<<(const rule& rule) {
    for (iterator it = rule.begin(); it != rule.end(); it++) {
        operator<<(*it);
    }
    return *this;
}

/// \brief Returns the identifier for this rule in the specified grammar
int rule::identifier(const grammar& gram) const {
    if (&gram == m_LastGrammar) return m_Identifier;

    m_LastGrammar = &gram;
    return m_Identifier = gram.identifier_for_rule(*this);
}
<|endoftext|>


<commit_before>/*
 * This file is part of TelepathyQt4
 *
 * Copyright (C) 2010 Collabora Ltd. <http://www.collabora.co.uk/>
 * Copyright (C) 2010 Nokia Corporation
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

#include <TelepathyQt4/AccountSet>
#include "TelepathyQt4/account-set-internal.h"

#include "TelepathyQt4/_gen/account-set.moc.hpp"
#include "TelepathyQt4/_gen/account-set-internal.moc.hpp"

#include "TelepathyQt4/debug-internal.h"

#include <TelepathyQt4/Account>
#include <TelepathyQt4/AccountManager>

namespace Tp
{

AccountSet::Private::Private(AccountSet *parent,
        const AccountManagerPtr &accountManager,
        const QVariantMap &filter)
    : parent(parent),
      accountManager(accountManager),
      filter(filter),
      ready(false)
{
    parent->connect(accountManager.data(),
            SIGNAL(accountCreated(const QString &)),
            SLOT(onAccountCreated(const QString &)));
    parent->connect(accountManager.data(),
            SIGNAL(accountRemoved(const QString &)),
            SLOT(onAccountRemoved(const QString &)));

    foreach (const QString &accountPath, accountManager->allAccountPaths()) {
        insertAccount(accountPath);
        ready = true;
    }
}

void AccountSet::Private::insertAccount(const QString &accountPath)
{
    Q_ASSERT(!wrappers.contains(accountPath));
    AccountPtr account = Account::create(accountManager->dbusConnection(),
                accountManager->busName(), accountPath);
    wrapAccount(account);
    filterAccount(account);
}

void AccountSet::Private::removeAccount(const QString &accountPath)
{
    Q_ASSERT(wrappers.contains(accountPath));
    accounts.remove(accountPath);
    AccountWrapper *wrapper = wrappers[accountPath];
    AccountPtr account = wrapper->account();
    delete wrapper;
    emit parent->accountRemoved(account);
}

void AccountSet::Private::wrapAccount(const AccountPtr &account)
{
    AccountWrapper *wrapper = new AccountWrapper(account, parent);
    parent->connect(wrapper,
            SIGNAL(accountPropertyChanged(const AccountPtr &, const QString &)),
            SLOT(onAccountPropertyChanged(const AccountPtr &, const QString &)));
    wrappers.insert(account->objectPath(), wrapper);
}

void AccountSet::Private::filterAccount(const AccountPtr &account)
{
    /* account changed, let's check if it matches filter */
    if (accountMatchFilter(account, filter)) {
        if (!accounts.contains(account->objectPath())) {
            accounts.insert(account->objectPath(), account);
            if (ready) {
                emit parent->accountAdded(account);
            }
        }
    } else {
        /* QHash::remove is no-op if the item is not in the hash */
        accounts.remove(account->objectPath());
        if (ready) {
            emit parent->accountRemoved(account);
        }
    }
}

bool AccountSet::Private::accountMatchFilter(const AccountPtr &account,
        const QVariantMap &filter)
{
    if (filter.isEmpty()) {
        return true;
    }

    bool match = true;
    QVariantMap::const_iterator i = filter.constBegin();
    QVariantMap::const_iterator end = filter.constEnd();
    while (i != end) {
        QString propertyName = i.key();
        QVariant propertyValue = i.value();

        if (account->property(propertyName.toLatin1().constData()) != propertyValue) {
            match = false;
            break;
        }

        ++i;
    }

    return match;
}

AccountSet::Private::AccountWrapper::AccountWrapper(
        const AccountPtr &account, QObject *parent)
    : QObject(parent),
      mAccount(account)
{
    connect(account.data(),
            SIGNAL(propertyChanged(const QString &)),
            SLOT(onAccountPropertyChanged(const QString &)));
}

AccountSet::Private::AccountWrapper::~AccountWrapper()
{
}

void AccountSet::Private::AccountWrapper::onAccountPropertyChanged(
        const QString &propertyName)
{
    emit accountPropertyChanged(mAccount, propertyName);
}

AccountSet::AccountSet(const AccountManagerPtr &accountManager,
        const QVariantMap &filter)
    : QObject(),
      mPriv(new Private(this, accountManager, filter))
{
}

AccountSet::~AccountSet()
{
}

AccountManagerPtr AccountSet::accountManager() const
{
    return mPriv->accountManager;
}

QVariantMap AccountSet::filter() const
{
    return mPriv->filter;
}

QList<AccountPtr> AccountSet::accounts() const
{
    return mPriv->accounts.values();
}

void AccountSet::onAccountCreated(const QString &accountPath)
{
    mPriv->insertAccount(accountPath);
}

void AccountSet::onAccountRemoved(const QString &accountPath)
{
    mPriv->removeAccount(accountPath);
}

void AccountSet::onAccountPropertyChanged(const Tp::AccountPtr &account,
        const QString &propertyName)
{
    mPriv->filterAccount(account);
}

} // Tp
<commit_msg>AccountSet: Properly connect to signals using namespace Tp:: where appropriate.<commit_after>/*
 * This file is part of TelepathyQt4
 *
 * Copyright (C) 2010 Collabora Ltd. <http://www.collabora.co.uk/>
 * Copyright (C) 2010 Nokia Corporation
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

#include <TelepathyQt4/AccountSet>
#include "TelepathyQt4/account-set-internal.h"

#include "TelepathyQt4/_gen/account-set.moc.hpp"
#include "TelepathyQt4/_gen/account-set-internal.moc.hpp"

#include "TelepathyQt4/debug-internal.h"

#include <TelepathyQt4/Account>
#include <TelepathyQt4/AccountManager>

namespace Tp
{

AccountSet::Private::Private(AccountSet *parent,
        const AccountManagerPtr &accountManager,
        const QVariantMap &filter)
    : parent(parent),
      accountManager(accountManager),
      filter(filter),
      ready(false)
{
    parent->connect(accountManager.data(),
            SIGNAL(accountCreated(const QString &)),
            SLOT(onAccountCreated(const QString &)));
    parent->connect(accountManager.data(),
            SIGNAL(accountRemoved(const QString &)),
            SLOT(onAccountRemoved(const QString &)));

    foreach (const QString &accountPath, accountManager->allAccountPaths()) {
        insertAccount(accountPath);
        ready = true;
    }
}

void AccountSet::Private::insertAccount(const QString &accountPath)
{
    Q_ASSERT(!wrappers.contains(accountPath));
    AccountPtr account = Account::create(accountManager->dbusConnection(),
                accountManager->busName(), accountPath);
    wrapAccount(account);
    filterAccount(account);
}

void AccountSet::Private::removeAccount(const QString &accountPath)
{
    Q_ASSERT(wrappers.contains(accountPath));
    accounts.remove(accountPath);
    AccountWrapper *wrapper = wrappers[accountPath];
    AccountPtr account = wrapper->account();
    delete wrapper;
    emit parent->accountRemoved(account);
}

void AccountSet::Private::wrapAccount(const AccountPtr &account)
{
    AccountWrapper *wrapper = new AccountWrapper(account, parent);
    parent->connect(wrapper,
            SIGNAL(accountPropertyChanged(const Tp::AccountPtr &, const QString &)),
            SLOT(onAccountPropertyChanged(const Tp::AccountPtr &, const QString &)));
    wrappers.insert(account->objectPath(), wrapper);
}

void AccountSet::Private::filterAccount(const AccountPtr &account)
{
    /* account changed, let's check if it matches filter */
    if (accountMatchFilter(account, filter)) {
        if (!accounts.contains(account->objectPath())) {
            accounts.insert(account->objectPath(), account);
            if (ready) {
                emit parent->accountAdded(account);
            }
        }
    } else {
        /* QHash::remove is no-op if the item is not in the hash */
        accounts.remove(account->objectPath());
        if (ready) {
            emit parent->accountRemoved(account);
        }
    }
}

bool AccountSet::Private::accountMatchFilter(const AccountPtr &account,
        const QVariantMap &filter)
{
    if (filter.isEmpty()) {
        return true;
    }

    bool match = true;
    QVariantMap::const_iterator i = filter.constBegin();
    QVariantMap::const_iterator end = filter.constEnd();
    while (i != end) {
        QString propertyName = i.key();
        QVariant propertyValue = i.value();

        if (account->property(propertyName.toLatin1().constData()) != propertyValue) {
            match = false;
            break;
        }

        ++i;
    }

    return match;
}

AccountSet::Private::AccountWrapper::AccountWrapper(
        const AccountPtr &account, QObject *parent)
    : QObject(parent),
      mAccount(account)
{
    connect(account.data(),
            SIGNAL(propertyChanged(const QString &)),
            SLOT(onAccountPropertyChanged(const QString &)));
}

AccountSet::Private::AccountWrapper::~AccountWrapper()
{
}

void AccountSet::Private::AccountWrapper::onAccountPropertyChanged(
        const QString &propertyName)
{
    emit accountPropertyChanged(mAccount, propertyName);
}

AccountSet::AccountSet(const AccountManagerPtr &accountManager,
        const QVariantMap &filter)
    : QObject(),
      mPriv(new Private(this, accountManager, filter))
{
}

AccountSet::~AccountSet()
{
}

AccountManagerPtr AccountSet::accountManager() const
{
    return mPriv->accountManager;
}

QVariantMap AccountSet::filter() const
{
    return mPriv->filter;
}

QList<AccountPtr> AccountSet::accounts() const
{
    return mPriv->accounts.values();
}

void AccountSet::onAccountCreated(const QString &accountPath)
{
    mPriv->insertAccount(accountPath);
}

void AccountSet::onAccountRemoved(const QString &accountPath)
{
    mPriv->removeAccount(accountPath);
}

void AccountSet::onAccountPropertyChanged(const Tp::AccountPtr &account,
        const QString &propertyName)
{
    mPriv->filterAccount(account);
}

} // Tp
<|endoftext|>