function X = factorfeature(varargin)
% FACTORFEATURE Feature vector associated with some variables for a factor
% 
% X = FACTORFEATURE(N,T,R) where N is the list of variables, T is
% the associated factortemplate, and R is the observation feature
% vector.
%
% X = FACTORFEATURE Creates an empty/default object
%
%  X = FACTORFEATURE(A) where A is a factorfeature object will
%  return a copy of A
  
% Fields:
%  vars
%  template
%  feature

    
% Jerod Weinman
% jerod@acm.org
    
% $Id: factorfeature.m 1 2009-05-07 13:41:00Z weinman $
 
% Jerod Weinman
% jerod@acm.org
% Copyright 2008, 2009, 2011
 
%    This file is part of MatLibFactorGraph.
%
%    MatLibFactorGraph is free software: you can redistribute it and/or modify
%    it under the terms of the GNU General Public License as published by
%    the Free Software Foundation, either version 3 of the License, or
%    (at your option) any later version.
%
%    MatLibFactorGraph 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 General Public License for more details.
%
%    You should have received a copy of the GNU General Public License
%    along with MatLibFactorGraph.  If not, see <http://www.gnu.org/licenses/>.

  if nargin == 0
	
	X.vars = [];
	X.template = factortemplate();
	X.feature = [];
	
	X = class(X,'factorfeature');
	
  elseif nargin==1 && isa(varargin{1},'factorfeature')
	
	X = varargin{1};
	
  else
	
	N = varargin{1};
	T = varargin{2};
	R = varargin{3};
	
	if ndims(N)>2 && ~any(size(N)==1)
	  error('N must be a vector of variables');
	end;
	
	N = N(:);
	
	if ~isa(T,'factortemplate')
	  error('T must be a factortemplate object');
	end;
	
	if numvars(T)~=length(N) && numvars(T)>0
	  error('Variable list N does not match number of variables T expects');
	end;
	
	% Let's let R be anything at all. Nice and general. Caveat emptor.
	
	X.vars = N;
	X.template = T;
	X.feature = R;
	
	X = class(X,'factorfeature');
	
  end;
  
