GraphLab: Distributed Graph-Parallel API  2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
any.cpp
1 /**
2  * Copyright (c) 2009 Carnegie Mellon University.
3  * All rights reserved.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing,
12  * software distributed under the License is distributed on an "AS
13  * IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
14  * express or implied. See the License for the specific language
15  * governing permissions and limitations under the License.
16  *
17  * For more about this software visit:
18  *
19  * http://www.graphlab.ml.cmu.edu
20  *
21  */
22 
23 
24 #include <graphlab/util/generics/any.hpp>
25 
26 namespace graphlab {
27 
28 
29  /**
30  * Define the static registry for any
31  */
32  any::registry_map_type& any::get_global_registry() {
33  static any::registry_map_type global_registry;
34  return global_registry;
35  }
36 
37 
38 
39  any::iholder* any::iholder::load(iarchive_soft_fail &arc) {
40  registry_map_type& global_registry = get_global_registry();
41  uint64_t idload;
42  arc >> idload;
43  registry_map_type::const_iterator iter = global_registry.find(idload);
44  if(iter == global_registry.end()) {
45  logstream(LOG_FATAL)
46  << "Cannot load object with hashed type [" << idload
47  << "] from stream!" << std::endl
48  << "\t A possible cause of this problem is that the type"
49  << std::endl
50  << "\t is never explicity used in this program.\n\n" << std::endl;
51  return NULL;
52  }
53  // Otherwise the iterator points to the deserialization routine
54  // for this type
55  return iter->second(arc);
56  }
57 
58 
59 } // end of namespace graphlab
60 
61 
62 std::ostream& operator<<(std::ostream& out, const graphlab::any& any) {
63  return any.print(out);
64 } // end of operator << for any
65