00001 00011 /* Copyright 2009 10gen Inc. 00012 * 00013 * Licensed under the Apache License, Version 2.0 (the "License"); 00014 * you may not use this file except in compliance with the License. 00015 * You may obtain a copy of the License at 00016 * 00017 * http://www.apache.org/licenses/LICENSE-2.0 00018 * 00019 * Unless required by applicable law or agreed to in writing, software 00020 * distributed under the License is distributed on an "AS IS" BASIS, 00021 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00022 * See the License for the specific language governing permissions and 00023 * limitations under the License. 00024 */ 00025 00026 #pragma once 00027 00028 #include "../util/optime.h" 00029 #include "../util/time_support.h" 00030 00031 namespace mongo { 00032 00038 inline BSONObjBuilder& BSONObjBuilder::appendTimestamp( const StringData& fieldName , unsigned long long time , unsigned int inc ) { 00039 OpTime t( (unsigned) (time / 1000) , inc ); 00040 appendTimestamp( fieldName , t.asDate() ); 00041 return *this; 00042 } 00043 00044 inline OpTime BSONElement::_opTime() const { 00045 if( type() == mongo::Date || type() == Timestamp ) 00046 return OpTime( *reinterpret_cast< const unsigned long long* >( value() ) ); 00047 return OpTime(); 00048 } 00049 00050 inline string BSONElement::_asCode() const { 00051 switch( type() ) { 00052 case mongo::String: 00053 case Code: 00054 return string(valuestr(), valuestrsize()-1); 00055 case CodeWScope: 00056 return string(codeWScopeCode(), *(int*)(valuestr())-1); 00057 default: 00058 log() << "can't convert type: " << (int)(type()) << " to code" << endl; 00059 } 00060 uassert( 10062 , "not code" , 0 ); 00061 return ""; 00062 } 00063 00064 inline BSONObjBuilder& BSONObjBuilderValueStream::operator<<(DateNowLabeler& id) { 00065 _builder->appendDate(_fieldName, jsTime()); 00066 _fieldName = 0; 00067 return *_builder; 00068 } 00069 00070 inline BSONObjBuilder& BSONObjBuilderValueStream::operator<<(MinKeyLabeler& id) { 00071 _builder->appendMinKey(_fieldName); 00072 _fieldName = 0; 00073 return *_builder; 00074 } 00075 00076 inline BSONObjBuilder& BSONObjBuilderValueStream::operator<<(MaxKeyLabeler& id) { 00077 _builder->appendMaxKey(_fieldName); 00078 _fieldName = 0; 00079 return *_builder; 00080 } 00081 00082 }