00001 /* 00002 * Copyright (c) 2009 Yahoo! Inc. All rights reserved. The copyrights 00003 * embodied in the content of this file are licensed under the BSD 00004 * (revised) open source license. 00005 * 00006 * This program is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License as published by 00008 * the Free Software Foundation; either version 3 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * Written (W) 2011 Shashwat Lal Das 00012 * Adaptation of Vowpal Wabbit v5.1. 00013 * Copyright (C) 2011 Berlin Institute of Technology and Max-Planck-Society. 00014 */ 00015 00016 #include <shogun/classifier/vw/cache/VwCacheReader.h> 00017 00018 using namespace shogun; 00019 00020 CVwCacheReader::CVwCacheReader() 00021 : CSGObject() 00022 { 00023 fd = -1; 00024 env = NULL; 00025 } 00026 00027 CVwCacheReader::CVwCacheReader(char * fname, CVwEnvironment* env_to_use) 00028 : CSGObject() 00029 { 00030 fd = open(fname, O_RDONLY); 00031 00032 if (fd < 0) 00033 SG_SERROR("Error opening the file %s for reading from cache!\n"); 00034 00035 env = env_to_use; 00036 SG_REF(env); 00037 } 00038 00039 CVwCacheReader::CVwCacheReader(int32_t f, CVwEnvironment* env_to_use) 00040 : CSGObject() 00041 { 00042 fd = f; 00043 env = env_to_use; 00044 SG_REF(env); 00045 } 00046 00047 CVwCacheReader::~CVwCacheReader() 00048 { 00049 // Does not attempt to close file as it could have been passed 00050 // from oustide 00051 if (env) 00052 SG_UNREF(env); 00053 } 00054 00055 void CVwCacheReader::set_file(int32_t f) 00056 { 00057 fd = f; 00058 } 00059 00060 void CVwCacheReader::set_env(CVwEnvironment* env_to_use) 00061 { 00062 env = env_to_use; 00063 SG_REF(env); 00064 } 00065 00066 CVwEnvironment* CVwCacheReader::get_env() 00067 { 00068 SG_REF(env); 00069 return env; 00070 }