/* ---------------------------------------------------------------------------- * GTSAM Copyright 2010, Georgia Tech Research Corporation, * Atlanta, Georgia 30332-0415 * All Rights Reserved * Authors: Frank Dellaert, et al. (see THANKS for the full author list) * See LICENSE for the license information * -------------------------------------------------------------------------- */ /** * @file DiscreteKey.h * @brief specialized key for discrete variables * @author Frank Dellaert * @date Feb 28, 2011 */ #pragma once #include #include #include #include #include namespace gtsam { /** * Key type for discrete variables. * Includes Key and cardinality. */ using DiscreteKey = std::pair; /// DiscreteKeys is a set of keys that can be assembled using the & operator struct GTSAM_EXPORT DiscreteKeys: public std::vector { // Forward all constructors. using std::vector::vector; /// Constructor for serialization DiscreteKeys() : std::vector::vector() {} /// Construct from a key explicit DiscreteKeys(const DiscreteKey& key) { push_back(key); } /// Construct from cardinalities. explicit DiscreteKeys(std::map cardinalities) { for (auto&& kv : cardinalities) emplace_back(kv); } /// Construct from a vector of keys DiscreteKeys(const std::vector& keys) : std::vector(keys) { } /// Construct from cardinalities with default names DiscreteKeys(const std::vector& cs); /// Return a vector of indices KeyVector indices() const; /// Return a map from index to cardinality std::map cardinalities() const; /// Add a key (non-const!) DiscreteKeys& operator&(const DiscreteKey& key) { push_back(key); return *this; } }; // DiscreteKeys /// Create a list from two keys DiscreteKeys operator&(const DiscreteKey& key1, const DiscreteKey& key2); }