classdef TimestampDatabase < handle
    % TIMESTAMPDATABASE Timestamp Database class
    %  self = TIMESTAMPDATABASE (config)
    %
    %  Input:
    %   - config = Timestamp configuration INI file or an already-parsed 
    %     config structure, as produced by ROK_PARSE_CONFIG_INI().
    %     The structure must contain the following fields:
    %      - config.data_file = Timestamp data file; either an absolute path
    %        or path relative to the path of config INI file
    %      - config.date_offset = date offset between stored and actual
    %        timestamps
    %      - config.time_offset= time offset between stored and actual 
    %        timestamps
    %      - config.frame_offset = frame offset, in case first stored 
    %        timestamp does not correspond to frame #1.
    %
    %  Output:
    %   - self = @UbisenseDatabase instance
    %
    % Copyright (C) 2011-2012, Rok Mandeljc <rok.mandeljc@fe.uni-lj.si>
    
    properties (SetAccess = private, GetAccess = private)
        data;
        dateOffset = 0;
        timeOffset = 0;
        frameOffset = 0;
    end
    
    methods
        % Constructor
        function self = TimestampDatabase (config)
            %% Parse the config INI
            if ischar(config),
                config = rok_parse_config_ini(config);
            end
            
            %% Apply offsets
            self.dateOffset = config.date_offset;
            self.timeOffset = config.time_offset;
            self.frameOffset = config.frame_offset;
            
            %% *** Load Timestamp data ***
            dataFile = rok_path_find_file(config.data_file, config.source_ini_filename);
            
            fid = fopen(dataFile, 'r', 'l');
            self.data = fread(fid, Inf, 'double');
            fclose(fid);
        end
    end
end