SHOGUN  v2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
StreamingVwCacheFile.cpp
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 3 of the License, or
5  * (at your option) any later version.
6  *
7  * Written (W) 2011 Shashwat Lal Das
8  * Copyright (C) 2011 Berlin Institute of Technology and Max-Planck-Society
9  */
11 
12 using namespace shogun;
13 
15  : CStreamingFile()
16 {
17  init(C_NATIVE);
18 }
19 
21  : CStreamingFile()
22 {
23  init(cache_type);
24 }
25 
27  : CStreamingFile(fname, rw)
28 {
29  init(cache_type);
30 }
31 
33 {
34  SG_UNREF(env);
36 }
37 
39 {
41  len = 1;
42  else
43  len = -1;
44 }
45 
47 {
49  len = 1;
50  else
51  len = -1;
52 }
53 
55 {
56  if (env)
57  SG_UNREF(env);
58 
59  env = env_to_use;
60  SG_REF(env);
61 
63 
64  switch (cache_format)
65  {
66  case C_NATIVE:
68  return;
69  case C_PROTOBUF:
70  SG_ERROR("Protocol buffers cache support is not implemented yet!\n");
71  }
72 
73  SG_ERROR("Unexpected cache type to use for reading!\n");
74 }
75 
77 {
78  buf->reset_file();
79 
80  // Recheck the cache so the parser can directly proceed with the examples
81  if (cache_format == C_NATIVE)
82  ((CVwNativeCacheReader*) cache_reader)->check_cache_metadata();
83 }
84 
85 void CStreamingVwCacheFile::init(EVwCacheType cache_type)
86 {
87  cache_format = cache_type;
88  env = new CVwEnvironment();
89 
90  switch (cache_type)
91  {
92  case C_NATIVE:
94  return;
95  case C_PROTOBUF:
96  SG_ERROR("Protocol buffers cache support is not implemented yet!\n");
97  }
98 
99  SG_ERROR("Unrecognized cache type to read from!\n");
100 }

SHOGUN Machine Learning Toolbox - Documentation